code to calculate the number of days between two dates

Answers were Sorted based on User's Feedback



code to calculate the number of days between two dates..

Answer / nikhil

<script language="javascript">
Date.prototype.DaysBetween = function()
{
var intMilDay = 24 * 60 * 60 * 1000;
var intMilDif = arguments[0] - this;
var intDays = Math.floor(intMilDif/intMilDay);
return intDays;
}
var d1 = new Date("06/01/2008");
var d2 = new Date("07/31/2008");
alert(d1.DaysBetween(d2));
var d3=d1.DaysBetween(d2);
document.write(d3);

</script>

Is This Answer Correct ?    8 Yes 6 No

code to calculate the number of days between two dates..

Answer / 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

More JavaScript Code Interview Questions

how to create Expandable and Collapsible Menus

0 Answers  


create Drop-Down Navigation Menus

0 Answers   TCS,


code to sorting an array of objects

0 Answers  


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

0 Answers  


sample code to auto focusing the first field in a form

0 Answers   Wipro,






How to Add Message and Confirmation Boxes Using JavaScript?

1 Answers  


how to get the User's Time of Day

0 Answers   HCL,


code to images to rollover

0 Answers  


code to calculate the number of days between two dates

2 Answers  


write a program segment that will ask the user if he wants to computer the perimeter of the area of the triangle. if the perimeter is wanted, ask the measure of the three sides and compute for the perimeter. if the area is wanted, ask for the measures of the base and height and compute for the area. display the computed value

1 Answers  


How to block double clicks

0 Answers  


Code for Adding Message and Confirmation Boxes Using JavaScript?

1 Answers  


Categories
  • PHP Code Interview Questions PHP Code (33)
  • JSP Code Interview Questions JSP Code (6)
  • ASP Code Interview Questions ASP Code (5)
  • CGI Perl Code Interview Questions CGI Perl Code (3)
  • JavaScript Code Interview Questions JavaScript Code (63)
  • VB Script Code Interview Questions VB Script Code (20)
  • Shell Script Code Interview Questions Shell Script Code (31)
  • Python Code Interview Questions Python Code (34)
  • WinRunner Code Interview Questions WinRunner Code (1)
  • HTML DHTML XHTML Code Interview Questions HTML DHTML XHTML Code (13)
  • XML Interview Questions XML (43)
  • Scripts_Markup Code AllOther Interview Questions Scripts_Markup Code AllOther (5)