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

write a code to generate pseudorandom numbes

0 Answers   ABC,


program to show a progress bar

0 Answers   Infosys,


maximizing the main window

0 Answers  


Reading which Character Key was pressed

1 Answers  


Create a ViewState Property?

0 Answers   TCS,






code to detect availability of cookies

0 Answers  


write a program to detect the user's browser ?

1 Answers   Infosys,


advance the focus to next consecutive fields when Enter Key is pressed

0 Answers   TCS,


how to pass data between pages using Cookies

0 Answers  


<html> <head> <title>BASIC CALCULATOR</title> </head> <script language= "javascript"> function= setValue(){ var a_term1 </script> <body> <center> <table> <tr> <td><input type="text" id="text box1" style="width:50px"> </td> <td><input type="text" id="text box2" style="width:40px"> </td> <td><input type="text" id="text box3" style="width:50px"> </td> </tr> </table> <table> <tr> <td><input type="text" id="text box4" ></td> </tr> </table> <table> <tr> <td><input type= "button" value= "7" onClick="" ></td> <td><input type= "button" value= "8" onClick="" ></td> <td><input type= "button" value= "9" onClick="" ></td> <td><input type= "button" value= "/" onClick="" ></td> </tr> <td><input type= "button" value= "4" onClick="" ></td> <td><input type= "button" value= "5" onClick="" ></td> <td><input type= "button" value= "6" onClick="" ></td> <td><input type= "button" value= "*" onClick="" ></td> </tr> <td><input type= "button" value= "1" onClick="" ></td> <td><input type= "button" value= "2" onClick="" ></td> <td><input type= "button" value= "3" onClick="" ></td> <td><input type= "button" value= "-" onClick="" ></td> </tr> <td><input type= "button" value= "0" onClick="" ></td> <td><input type= "button" value= "C" onClick="" ></td> <td><input type= "button" value= "=" onClick="" ></td> <td><input type= "button" value= "+" OnClick="" ></td> </table> </center> </body> <hr/> </html> how do i make the calculator work now

1 Answers  


I have a doubt regarding including tags in a function. I have written a function in javascript in a html page. The function got called by clicking a button, i want to display the results in same html page by placing tags in the function. (this hmtl page is static page) Is this possible? example: <SCRIPT LANGUAGE=javascript> function calSubmit_onclick() { var xyz=0; .......... .......... document.write("<lable>"+xyz+"</label>"); /*Is it possible*/ }

0 Answers  


code to set the main window's size

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)