code to calculate the number of days between two dates

Answer Posted / nagaraj

function getDaysMinusWeekend(startDay, startMonth,
startYear, endDay, endMonth, endYear) { var sdate = new Date
(); var edate = new Date(); var odays = 0; var total =
0; sdate.setFullYear(startYear,startMonth,startDay);
edate.setFullYear(endYear,endMonth,endDay);
odays = 6 - sdate.getDay(); if(odays == 6) {
odays = 0; } sdate.setFullYear
(startYear,startMonth,startDay + odays); return
Math.floor(((((edate.getTime() - sdate.getTime()) / 1000 /
60 / 60 / 24) / 7) * 5) + odays);}// ########## startMonth
and endMonth both start at 0 i.e 0 = january, 1 = feb etc
function getDaysMinusWeekend(startDay, startMonth,
startYear, endDay, endMonth, endYear) {
var sdate = new Date();
var edate = new Date();
var odays = 0;
var total = 0;

sdate.setFullYear(startYear,startMonth,startDay);
edate.setFullYear(endYear,endMonth,endDay);

odays = 6 - sdate.getDay();
if(odays == 6) {
odays = 0;
}

sdate.setFullYear(startYear,startMonth,startDay +
odays);

return Math.floor(((((edate.getTime() -
sdate.getTime()) / 1000 / 60 / 60 / 24) / 7) * 5) +

odays);
}

Is This Answer Correct ?    4 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

determine which Element received an Event

1905


how to create a Custom Scrollbar

2050


how to create Expandable and Collapsible Menus

2656


code to keep a page Out of the browser history

1653


write a code to generate pseudorandom numbes

1786






code to sorting an array of objects

1987


code to positioning of window in certain dimensions

1666


how to pass data between pages using Frames

2147


maximizing the main window

1636


code to create a new window

1754


how to create a Draggable element

1968


how to create an anonymous function

1732


snippet to prevent submission of form when certain/any validations got failed

1548


program to bring a window to the front

1568


how to copy form data between different pages

1678