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.

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.

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.