
How to compare dates and display the difference in terms of days?

<html>
<head>
<script language="JavaScript">
var date1 = new Date("jan, 25, 2010");
var today = new Date();
var difference = today - date1;
var days =parseInt(difference / (1000 * 60 * 60 * 24));
document.writeln("Number of days: "+days);
</script>
</head>
</html>
Description: In javascript whenever you write new Date() it shows the current date in standard format with current day,date,time and GMT.you can also specify your own date by using new Date(). You can compare dates and get days difference between the dates. ParseInt() is used here to convert the days in integer.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.