Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working Days From Date1 to Date2 1

Status
Not open for further replies.

PDL

IS-IT--Management
Dec 11, 2000
36
0
0
US
Anyone have an algorithm that would calculate/display the number of working days (assuming 5 days/week) from Date1 to Date2??

 
PDL, this is quite a hard one, because of all the differences among countries and possible exceptions. For example, are all ordinary weekdays (not saturday or sunday) workdays, or should for example Christmas and the 4th of July (for the US) excluded? Think about these questions first, then we can help. Good luck...


<webguru>iqof188</webguru>
 
I would be tickled with a simple solution that assumes Saturday/Sundays are NOT work days and do NOT count any holidays at all...

Reason, one would easily say:

Days Remaining = NewDateFunction(Date1,Date2) - Holidays

I would just use the old grey matter to get the &quot;Holidays&quot; number.

Thanks!
 
so you're only looking for NewDateFunction(Date1,Date2) right ??
i would use DateDiff to get the number of days between Date1 and Date2
then use a which-day-in-week (i know there is one in cf !!) function to know how far from a sunday/saturday i'm starting to count (and keep that difference stored somewhere)
then i guess (number_of_days modulo 7) * 5 + the_difference_you_stored is the answer
but it's rather an algorithm/mathematical advice you were looking for, NOT a cf one !!!! so this post shouldn't have been in the cf forum ... !
 
I think this will do what you want. It starts with the day after sDate and counts days up to and including eDate.

<cfset workDays=0>
<cfloop index=&quot;x&quot; from=1 to=#datediff(&quot;d&quot;,sDate,eDate)#>
<cfif dayofweek( dateAdd(&quot;d&quot;,x,sDate)) neq 1 and dayofweek( dateAdd(&quot;d&quot;,x,sDate)) neq 7>
<cfset workDays=workDays + 1>
</cfif>
</cfloop>

Hope this helps,
GJ
 
I've thought about that one GunJack, but it is VERY slow. :)There must be a faster way to do that, I'll think about an alternative.




<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top