How to get total number of working days in a month of current year

Hi Team,

I need to get total networking days of current month, say for example now we are in Feb so i need total working days of Feb month similarly wen i will be in march i need to get total working days of march like this i need to get dynamic count of every current month to do some other calculation.

HI @bhanupriya.cb

Check out this video link

Regards
Gokul

@bhanupriya.cb

Please follow

In_monthnumber,in_year in integer format

Out_days as integer and initilaize with 0

Startdate = New datetime(in_year,in_month,1)
Enddate = New DateTime(in_year,in_month,DateTime.DaysInMonth(in_year,in_month))

  1. Use a while loop and give the condition as startdate >= enddate
  2. Inside the loop use a if condition
    Startdate.dayofweek.ToString.ToLower.Equals("sunday") Or startdate.dayofweek.ToString.ToLower.Equals("saturday")
  3. On the else side use assign with out_days = out_days+1 and on then side do nothing
  4. After the if condition use another assign with strtdate = startdate.adddays(1)

At the end of loop you will have the number of workingdays in out_days variable

Cheers

Hi @bhanupriya.cb ,

Maybe an Alternate method :

Enumerable.Range(0,DateTime.DaysInMonth(Now.Year,Now.Month)).Where(Function(x)Not({"Sunday","Saturday"}.Any(Function(m)(new DateTime(Now.Year,Now.Month,1)).AddDays(x).DayOfWeek.ToString.Equals(m)))).Count

Here, {"Sunday","Saturday"} is preferred as the non-working days in a week. If you do have a list of holidays also based on your/Client Calendar, we could prepare it and also use it in the Expression above to exclude these dates.

Test the above expression and let us know if this is sufficient for your case.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.