date calculations

1. Junior Member
Join Date
Dec 1969
Posts
3

date calculations

I need to calculate x number of days which are workdays between a date in my database and today. Can somebody please help me? I am having problems figuring out the code that will create an array with each date in between firstdate and lastdate, take out all the dates which are sundays and count the remainder, so that if I need 18 days ago from the day in the database, it will give me a date 18 WORKDAYS ago....NO SUNDAYS INCLUDED<BR><BR>Someone please help!

2. Senior Member
Join Date
Dec 1969
Posts
96,118

You don't need an array...

The code is *easy* IF (a big IF!) you don&#039;t worry about holidays!<BR><BR>One very, very simple way to do it:<BR><BR>&#060;%<BR>startDate = CDate( Request("startDate") )<BR>endDate = CDate( Request("endDate") )<BR>count = 0<BR>curDate = startDate<BR>Do Until curDate &#062;= endDate<BR>&nbsp; &nbsp; If WeekDay(curDate) &#060;&#062; vbSunday Then count=count+1<BR>&nbsp; &nbsp; curDate = curDate + 1<BR>Loop<BR><BR>Response.Write "There are " & count & " non-Sunday days between " _<BR>&nbsp; &nbsp; &nbsp; &nbsp; & startDate & " and " & endDate & "&#060;HR&#062;"<BR><BR>%&#062;<BR><BR>If the period in question isn&#039;t longer than a couple of months, that&#039;s also a reasonably efficient way to do it. If you start talking about years between dates, then we need to find a better way.<BR><BR>

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•