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 images to rollover

1860


sample code to auto focusing the first field in a form

2033


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:


code to keep a page Out of the browser history

1653


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

1738


Create a ViewState Property?

2286


create Drop-Down Navigation Menus

1705


how to create Expandable and Collapsible Menus

2656


how to create an anonymous function

1732


how to create a Custom Scrollbar

2050


code to positioning of window in certain dimensions

1666


how to Scroll a DIV content

2161


How to block double clicks

1622