Jul 24, 2003 #1 haydn Technical User Mar 16, 2002 40 GB I know it's probably obvious, but I need to simply calculate the number of working days between two dates.
I know it's probably obvious, but I need to simply calculate the number of working days between two dates.
Jul 24, 2003 #2 1chicken Programmer Jun 11, 2003 20 US Try using this in your record or group selection formula: not(dayofweek({Table.Date_Field)) in [1,7]) then count the days without having to worry about the weekend. Upvote 0 Downvote
Try using this in your record or group selection formula: not(dayofweek({Table.Date_Field)) in [1,7]) then count the days without having to worry about the weekend.
Jul 24, 2003 #3 Naith Programmer May 14, 2002 2,530 GB Have a look at the formula section on Ken Hamady's website. http://www.kenhamady.com. There is a formula or two there which handles what you want. Naith Upvote 0 Downvote
Have a look at the formula section on Ken Hamady's website. http://www.kenhamady.com. There is a formula or two there which handles what you want. Naith
Jul 24, 2003 #4 FloridaHawk Programmer Jun 20, 2003 19 US This is what I made last week for the exact same problem works great. Have it set up so you can test in any report: // use this to text forumla- later remove TestDate (and currentdatetime if apply)and enter the field name(s) datetimevar TestDate := datetime(2002,12,01); numberVar BusSec := (datediff("s",TestDate,CurrentDateTime)) - ((If datepart("yyyy",currentdatetime) = datepart("yyyy",TestDate) THEN datepart("ww",currentdatetime) - datePart ("ww",TestDate) ELSE ((((datepart("yyyy",currentdatetime) - datepart("yyyy",TestDate)) * 52) + datepart("ww",currentdatetime))) - datePart ("ww",TestDate)) * (86400*2)); NumberVar AvgSecs := BusSec; NumberVar secs := (AvgSecs Mod 60); NumberVar mins := (AvgSecs\60 Mod 60); NumberVar hours := (AvgSecs\ 3600 Mod 24); NumberVar days := AvgSecs\ 3600 \ 24; StringVar HH := totext(truncate(hours)); StringVar MM := totext(truncate(mins)); StringVar SS := totext(round(secs, 0)); StringVar DD := totext(truncate(days)); DD + " " + "Days" + " " + HH +"hrs"+ " " + MM+"Min" + " " +SS //Create if statement for grouping Upvote 0 Downvote
This is what I made last week for the exact same problem works great. Have it set up so you can test in any report: // use this to text forumla- later remove TestDate (and currentdatetime if apply)and enter the field name(s) datetimevar TestDate := datetime(2002,12,01); numberVar BusSec := (datediff("s",TestDate,CurrentDateTime)) - ((If datepart("yyyy",currentdatetime) = datepart("yyyy",TestDate) THEN datepart("ww",currentdatetime) - datePart ("ww",TestDate) ELSE ((((datepart("yyyy",currentdatetime) - datepart("yyyy",TestDate)) * 52) + datepart("ww",currentdatetime))) - datePart ("ww",TestDate)) * (86400*2)); NumberVar AvgSecs := BusSec; NumberVar secs := (AvgSecs Mod 60); NumberVar mins := (AvgSecs\60 Mod 60); NumberVar hours := (AvgSecs\ 3600 Mod 24); NumberVar days := AvgSecs\ 3600 \ 24; StringVar HH := totext(truncate(hours)); StringVar MM := totext(truncate(mins)); StringVar SS := totext(round(secs, 0)); StringVar DD := totext(truncate(days)); DD + " " + "Days" + " " + HH +"hrs"+ " " + MM+"Min" + " " +SS //Create if statement for grouping
Jul 25, 2003 #5 Reebo99 MIS Jan 24, 2003 1,074 GB If this is just weekdays you can use : DateDiff ("d", {StartDateField}, {EndDateField}) - DateDiff ("ww", {StartDateField}, {EndDateField}, crSaturday) - DateDiff ("ww", {StartDateField}, {EndDateField}, crSunday) Hope this helps..... Reebo Scotland (Sunny with a Smile) Upvote 0 Downvote
If this is just weekdays you can use : DateDiff ("d", {StartDateField}, {EndDateField}) - DateDiff ("ww", {StartDateField}, {EndDateField}, crSaturday) - DateDiff ("ww", {StartDateField}, {EndDateField}, crSunday) Hope this helps..... Reebo Scotland (Sunny with a Smile)
Jul 25, 2003 #6 mbarron Technical User Aug 3, 2001 1,247 US Reebo, The formula you provided has one minor flaw. It does not count the first day if it falls on a weekday. (see this thread thread149-304415) A check for the the DOW of the first date in the range can be added to add that day to the total. numbervar days ; days:= DateDiff ("d", {StartDateField}, {EndDateField}) - DateDiff ("ww", {StartDateField},EndDateField},crSaturday) - DateDiff ("ww", {StartDateField}, {EndDateField}, crSunday) if dayofweek(StartDateField) in [2,3,4,5,6] then days:=days+1; days If you have CR8 or above, here is a loop I created to count days. datevar firstday:={StartDateField}); datevar lastday:={EndDateField}; numbervar loop; local numbervar wds; numbervar span; span:=lastday-firstday; For loop:= 0 to span do( if dayofweek(firstday+loop)in [2 to 6] then wds:=wds+1 else wds:=wds); wds Mike Upvote 0 Downvote
Reebo, The formula you provided has one minor flaw. It does not count the first day if it falls on a weekday. (see this thread thread149-304415) A check for the the DOW of the first date in the range can be added to add that day to the total. numbervar days ; days:= DateDiff ("d", {StartDateField}, {EndDateField}) - DateDiff ("ww", {StartDateField},EndDateField},crSaturday) - DateDiff ("ww", {StartDateField}, {EndDateField}, crSunday) if dayofweek(StartDateField) in [2,3,4,5,6] then days:=days+1; days If you have CR8 or above, here is a loop I created to count days. datevar firstday:={StartDateField}); datevar lastday:={EndDateField}; numbervar loop; local numbervar wds; numbervar span; span:=lastday-firstday; For loop:= 0 to span do( if dayofweek(firstday+loop)in [2 to 6] then wds:=wds+1 else wds:=wds); wds Mike