I want to count the number of days between two dates excluding saturday and sundays. So if the strt date was thursday the 16th and the end date monday the 20th the count of days would be 2 not 4.
Thank you.
I am using Crystal Reports
Nevermind, I found a formla that seems to work.
DateDiff ("d",{probsummarym1.open_time},{probsummarym1.resolved_time}) -
datediff("ww", {probsummarym1.open_time},{probsummarym1.resolved_time},crSaturday)-
datediff("ww", {probsummarym1.open_time},{probsummarym1.resolved_time},crSunday) <= 5
Now I just need to figure out how to subtract holidays as well...
I think that the following came from one of Ken Hamady's newsletters some time ago, just cut & paste into a formula field:
The number of "Work Days" between two dates:
Calculating the number of calendar days between two dates is fairly simple. However, if you need to calculate the number of work days, it gets a bit more difficult. Not only do you have to account for weekends, in many instances you also have to account for holidays, which change each year.
The formula below does both, but it requires that you enter your list of holiday dates in the last section. This list must be kept up to date and updated each year. The list should include only holidays that will occur during the work week. You can include more than one year of holidays in the list if you want. To use this formula, simply copy it into your report and put your field names in on the second and third lines in place of the field names I have used.
NOTE - this formula counts both the starting date AND the ending date, if both are work days. So if you start Monday and end Tuesday, that is 2 days.
WhilePrintingRecords;
DateVar Start := {table.StartDate}; //Replace this field with your Starting Date field
DateVar End := {table.EndDate}; //Replace this field with your Ending Date field
NumberVar Weeks;
NumberVar Days;
NumberVar Hol:= 0;
//Figure the number of Calendar "Rows" involved and count 5 days for each:
Weeks:= (Truncate (End - dayofWeek(End) + 1 - (Start - dayofWeek(Start) + 1)) /7 ) * 5;
//Adjust the first and last weeks based on when in the week you start and end
Days := DayOfWeek(End) - DayOfWeek(Start) + 1
+ (if DayOfWeek(Start) = 1 then -1 else 0) //adjust for starting on a Sunday:
+ (if DayOfWeek(End) = 7 then -1 else 0); //adjust for ending on a Saturday:
//Adjust for Holidays in the period between the start and end dates:
if Date(1999,01,01) in start to end then Hol:= Hol+1 else Hol:= Hol;
if Date(1999,01,18) in start to end then Hol:= Hol+1 else Hol:= Hol;
if Date(1999,02,16) in start to end then Hol:= Hol+1 else Hol:= Hol;
if Date(1999,05,31) in start to end then Hol:= Hol+1 else Hol:= Hol;
//Assemble the adjusted work days
Weeks + Days - Hol
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.