Tracking business days in VBScript

Results 1 to 2 of 2

Thread: Tracking business days in VBScript

  1. #1
    Mark Petersen Guest

    Default Tracking business days in VBScript

    I want to send an automated email 5 business days after a user submits a form. Is there some built-in logic to track business days in ASP?

  2. #2
    Join Date
    Dec 1969

    Default RE: Tracking business days in VBScript

    Maybe I should ask to put this in the FAQ, also. I just created this page in response to another question last week.<BR><BR>Nothing built in, per se, but try the technique on this demo page.<BR><BR>NOTE: Does *NOT* account for holidays! <BR><BR>NOTE: Treats Saturday and Sunday as being same as *following* Monday! So three days from Sunday is Thursday, same as when you start from Monday.<BR><BR>***************<BR><BR><BR>&LT;HTML &#062;&LT;BODY&#062;<BR><BR>&LT;%<BR>Sub msg(n)<BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write n & "&LT;BR&#062;" & vbNewLine<BR>End Sub<BR><BR>&#039 this is a "shorthand" version of the longer and <BR>&#039 easier to read function:<BR>Function BizDays( d, n )<BR>&nbsp;&nbsp;&nbsp;&nbsp;j=WeekDay(d)-2<BR>&nbsp;&nbsp;&nbsp;&nbsp;b=n+j<BR>&nbsp;&nbsp; &nbsp;&nbsp;If j=-1 Then j=-2<BR>&nbsp;&nbsp;&nbsp;&nbsp;BizDays=DateAdd("d", (b MOD 5)-j, DateAdd("ww", b5, d ) )<BR>End Function<BR><BR>&#039 this function is longer but a lot easier to read and understand<BR>Function AddBizDays( byVal theDate, byVal numDays )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 we "back up" to Monday of the same week...<BR>&nbsp;&nbsp;&nbsp;&nbsp;adjust = WeekDay(theDate) - vbMonday<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 and then adjust the requested number of days by that amount<BR>&nbsp;&nbsp;&nbsp;&nbsp;numDays = numDays + adjust<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 but then adjust the adjustment, for Sundays only<BR>&nbsp;&nbsp;&nbsp;&nbsp;If adjust = -1 Then adjust = -2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 now "back up" the given date by the same number of days...<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 this backs us up to the preceding Monday (or doesn&#039t move<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 us if we are already on Monday, of course)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mondayDate = DateAdd("d", - adjust, theDate )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 then go forward by the number of weeks that are equivalent<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 to the requested number of business days...that is,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 one week every 5 business days<BR>&nbsp;&nbsp;&nbsp;&nbsp;futureDate = DateAdd("ww", numDays 5, mondayDate )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 finally, go forward by the number of days "left over"...<BR>&nbsp;&nbsp;&nbsp;&nbsp;AddBizDays = DateAdd("d", numDays MOD 5, futureDate )<BR>End Function<BR><BR>Sub show(d, n)<BR>&nbsp;&nbsp;&nbsp;&nbsp;msg "Starting on " & d & " and adding " & n _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;& " business days gives " & addBizDays(d,n) _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;& " (short form function: " & BizDays(d,n) & ")"<BR>End Sub<BR><BR>&#039 just some demos of the "correctness" of the functions:<BR>&#039<BR>show CDate("8/12/2000"), 3<BR>show CDate("8/13/2000"), 3<BR>show CDate("8/14/2000"), 3<BR>show CDate("8/15/2000"), 3<BR>show CDate("8/16/2000"), 3<BR>show CDate("8/14/2000"), 1<BR>show CDate("8/14/2000"), 2<BR>show CDate("8/14/2000"), 3<BR>show CDate("8/14/2000"), 4<BR>show CDate("8/14/2000"), 5<BR>show CDate("8/14/2000"), 6<BR>show CDate("8/14/2000"), 7<BR>show CDate("8/14/2000"), 8<BR>show CDate("8/14/2000"), 9<BR>show CDate("8/14/2000"), 10<BR>show CDate("8/14/2000"), 11<BR>show CDate("8/14/2000"), 20<BR>show CDate("8/14/2000"), 40<BR>show CDate("8/14/2000"), 60<BR><BR>%&#062;<BR>&LT;/BODY&#062;<BR>&LT;/HTML&#062;<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