Dr
Sun Jul 06 17:21:59 CDT 2003
JRS: In article <33HNa.70029$x4o.14817@news04.bloor.is.net.cable.rogers
.com>, seen in news:microsoft.public.scripting.vbscript, Atse
<dunggaze@yahoo.com> posted at Sat, 5 Jul 2003 21:03:59 :-
>
>I have 2 questions about counting weekdays.
>1. How can I count how many business days there are from date1(variable) to
>date2(variable)?
>like,
>x(weekdays) = date2() -date1()
>
>2. How can I know the day, moving x business days from date1(variable)?
>like,
>date2() = date1 + x(weekdays)
>
>Thanks for any idea.
On second thoughts, and if holidays are ignored :
To get the difference of two dates, or to go ahead X days, one does best
to work with a daycount, using functions for date -> daycount -> date.
Thus, for business days, do similarly with a business day count; this
will be simplest if zero-based starting on a long-ago Monday, say
1900-01-01. To go earlier, increase each 2 by a chosen multiple of 7.
function WDC(D) ' Date to Weekday Count
dim T, X
T = Clng(D) - 2
X = T mod 7 : if X>4 then X=4 ' odd days
WDC = 5 * (T\7) + X
end function
function CDW(N) ' Weekday Count to Date
CDW = CDate( 7 * (N\5) + N mod 5) + 2
end function
These are, very lightly, tested in
<URL:
http://www.merlyn.demon.co.uk/ws-dates.htm>
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:
http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:
http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:
http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.