0

how to calculate the days between two dates excluding saturday and sunday
foe example if i am calculating the days between 14/12/2007 to 17/12/2007
the answer for no of days should be 4...
pls send the code for above problem.
advance thanks
hidash.

3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by MidiMagic
0

how to calculate the days between two dates excluding saturday and sunday
foe example if i am calculating the days between 14/12/2007 to 17/12/2007
the answer for no of days should be 2...
pls send the code for above problem.
advance thanks
hidash.

0
var date1 = new Date();
var date2 = new Date();
var diff = new Date();

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

return (diff.getTime() / (1000 * 60 * 60 * 24));

theres the basics given that date1, date2 are the dates you wish to compare

0

it should be calculate only monday to friday and it should not calculate the saturday and sunday.
anyhow thanks funkus

0

You can get it within +/- two days (no matter the length of the interval) just by integer-dividing the the output of the above formula by 7, and then multiplying by 5.

To refine it more, you need to know what day of the week each day is, and add or subtract up to two days, according to which days of the week each day is.

If the start and end dates are the same day of the week, no adjustment is needed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.