code to calculate the number of days between two dates

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

code to detect availability of cookies

1920


code to keep a page Out of the browser history

1800


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

1894


code to create a new window

1919


program to bring a window to the front

1751






communication between main window and new windows

1880


how to create a Custom Scrollbar

2222


how to create Expandable and Collapsible Menus

2833


how to create an anonymous function

1872


how to convert between arrays and strings

2282


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

1706


how to pass data between pages using Cookies

2039


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

1871


determine which Element received an Event

2067


program to show a progress bar

2284