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

code to detect availability of cookies

0 Answers  


could you please tell me for what javac, javax,swing,awt.*; are using. what is the meaning and differences. and also there are 4 access modifiers in java. public, private, protected, default. what is the meaning of these 4 access modifiers and difference. public is the access modifier void means return data type disp() means function name what mean by static

1 Answers   Infosys,


How to encode and decode URL strings?

0 Answers   TCS,


how to Scroll a DIV content

0 Answers   SoftSquare,


code to keep a page Out of the browser history

0 Answers  






code to get the coordinates of a Click Event

0 Answers  


determine which key was pressed and its type

1 Answers  


how to transform XML Data into HTML

0 Answers  


write a code to generate pseudorandom numbes

0 Answers   ABC,


code to positioning of window in certain dimensions

0 Answers  


how to copy form data between different pages

0 Answers  


how to convert between arrays and strings

0 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)