JRS: In article <
[email protected]>, dated Tue, 25 Jan 2005
You could have copied it. Do not presume that the Subject line is readily
visible when the Body is being read. It is:
Calculate the number of WEEKDAYS between 2 dates?
i need a javascript to run this, but not in
Is VBScript an option? If so, look at "DateDiff()".
Cut-and-paste the following into an IE Address bar:
vbscript
ateDiff("d",#01/01/2005#,#01/26/2005#)
It would help if you were both to read and understand the question
before answering. Your code gives me 25.
The OP is posting from the UK; he cannot be expected to want FFF dates.
The difference in those dates is 25 days.
There are 24 days between those dates.
There are 17 weekdays between those dates, or 18 inclusive (Sat..Wed).
You could have answered with corresponding javascript:
javascript:Math.round((new Date("2005/01/26")-new Date("2005/01/01"))/864e5)
also gives 25 from the address bar.
You do not need DateDiff :
vbscript:CDate(#01/26/2005#)-CDate(#01/01/2005#)
and indeed vbscript:#01/26/2005#-#01/01/2005#
give 25 too.
The OP can find what he needs in js-date7.htm, via FAQ; see below.
He will have to consider the meaning of "between".
Alternatively, the following method will do well enough for short
intervals (adapt for desired end-effects) :
D = new Date("2005/01/01")
E = new Date("2005/01/26").setHours(12)
N = 0
while (D<E) {
if (D.getDay()%6!=0) N++
D.setDate(D.getDate()+1)
}
N