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

maximizing the main window

1645


function to combine two or more arrays

1711


Reading which Non-Character Key was pressed

1699


Create a Menu that can be activated while clicking on Right Mouse button

1717


create Drop-Down Navigation Menus

1716






how to create a Draggable element

1976


code to Hide and Show form controls

1818


code to images to rollover

1873


code to detect versions of different browsers like internet explorer, netscape, mozilla, opera etc

1749


how to Auto Scroll the page

1639


how to transform XML Data into HTML

1914


sample code to auto focusing the first field in a form

2039


how to get the User's Time of Day

1681


how to create Expandable and Collapsible Menus

2664


code to keep a page Out of the browser history

1669