Hi,

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.

Atse

Re: weekdays by Robert

Robert
Sat Jul 05 18:00:24 CDT 2003

you might want to try this, I found it on a google search:


Here's a routine I wrote in VB and converted to VBScript that gives
the number of business days between two dates:

'VBScript does not support the VBA function IIF
'so we can mimic it with this function
Function IIf(i,j,k)
If i Then IIf = j Else IIf = k
End Function

Date1 = CDate("4/1/01")
Date2 = CDate("5/16/01")

Dim days
Dim dowdiff
Dim weekd
days = DateDiff("d", Date1, Date2)
dowdiff = IIf(Weekday(Date1) < 7, Weekday(Date2), 1) _
- Weekday(Date1)
weekd = IIf(days = 0, 0, Int(days / 7) * 5 + _
IIf(dowdiff >= 0 And dowdiff < 6, dowdiff, dowdiff + 5))

Response.Write weekd


--
My E-mail address is rcohen@yourfears.bbhtx.org. If you
need to e-mail me off list just get rid of "your fears" and
drop me a line.


"Atse" <dunggaze@yahoo.com> wrote in message
news:33HNa.70029$x4o.14817@news04.bloor.is.net.cable.rogers.com...
> Hi,
>
> 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.
>
> Atse
>
>



Re: weekdays by Michael

Michael
Sat Jul 05 18:05:16 CDT 2003

Atse wrote:
> Hi,
>
> 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.
>
> Atse

Google Groups: View Thread "Get # of days between two dates excluding Sat &
Sun"
http://groups.google.com/groups?th=e3401054eed7aeb

The example doesn't account for holidays...


--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp


Re: weekdays by Michael

Michael
Sat Jul 05 18:26:45 CDT 2003


"Atse" <dunggaze@yahoo.com> wrote in message
news:33HNa.70029$x4o.14817@news04.bloor.is.net.cable.rogers.com...
: Hi,
:
: 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.
:
: Atse


This will include the start/end dates in the count, modify to suit

dt1 = DateSerial(2003, 7, 7)
dt2 = DateSerial(2003, 7, 14)
Do Until dt1 > dt2
If Weekday(dt1) Mod 7 > 1 Then workdays = workdays + 1
dt1 = dt1 + 1
Loop
MsgBox "Workdays = " & workdays


This needs a bit of testing, perhaps a tweak

dt1 = dateserial(2003,7,7)
if weekday(dt1) mod 7 < 2 then dt1 = dt1 + 2 - weekday(dt1) mod 7
wkDysAdd = 18
dt2 = dt1 + (wkDysAdd\5)*7 + (wkDysAdd mod 5)
if weekday(dt2) mod 7 < 2 then dt2 = dt2 + 2 - weekday(dt2) mod 7
if weekday(dt2) < weekday(dt1) then dt2 = dt2 + 2
msgbox dt2



Re: weekdays by Dr

Dr
Sun Jul 06 09:00:18 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.

The matter is treated, for javascript, in my
<URL:http://www.merlyn.demon.co.uk/js-date2.htm>, which, if nothing
better appears, you should be able to adapt.

Holidays, for BI & NA, are in
<URL:http://www.merlyn.demon.co.uk/holidays.htm>. If you're not BI or
NA, that's your problem; you should not ask locality-dependent questions
in an international medium without stating the applicable location(s).

If the length ahead is not great, there's probably no need to do better
than stepping a day at a time and considering the nature of each day.

For long periods, go to the next end of a weekend, then use a 5:7 rule,
seek holidays in between, etc.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Re: weekdays by Dr

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.