In comp.lang.javascript message <b40e2144-3e6f-43f7-a20f-e4c181432167@r3
g2000vbp.googlegroups.com>, Sun, 10 May 2009 06:58:56, gunso
How do i count number of saturdays and sundays in a function which
takes in 2 dates...
function countSatSun(startDate, endDate){
}
Should return me the total of saturdays and sundays between these
dates.
Ignore T(PE)L. He does not understand English as it is, unfortunately,
commonly written; and may be under the illusion that he is a normal
human being.
You need to be more exact about your dates; is the time component zero,
and should you be thinking in UTC or LCT - the former is more efficient,
the latter can only be truly needed if real time is involved.
You will also need to know what "between" means; do you count the days
themselves, or are they necessarily weekdays.
If the dates are necessarily not too far apart and not too numerous, you
only need to step D through every day and count; weekends are when
D.get[UTC}Day()%6==0. It would be %6==1 for ISO 8601.
Otherwise, allowing for Summer Time if needed, one gets from a Date
Object to a daycount by dividing by 864e5; take the difference, integer
divide by 7, multiply by 2. Having dealt with complete weeks, just
consider the remaining fractional week.
<URL:
http://www.merlyn.demon.co.uk/js-date7.htm> contains "Counting
Weekdays" etc., which should be sufficiently easy to adapt.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.