
I want to find the difference between two dates in terms of days. I am using javascript. Please help.

<html>
<head>
<script type="text/javascript">
var date1=new Date();
var date2 =new Date("Jan, 11, 2000")
var yearDiff=date1.getFullYear()-date2.getFullYear();
var y1=date1.getFullYear();
var y2=date2.getFullYear();;
var monthDiff=(date1.getMonth() + y1*12)-(date2.getMonth() +y2*12);
var day1=date1.getDay();
var day2=date2.getDay();
var dayDiff=(day1-day2) + (monthDiff*30);
document.write("Number of day difference : "+dayDiff);
</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 get number of years of specified date by using getFullYear() function, number of months by using getMonth() method and number of days by using method getDay(). Now to find date difference in days you must consider years and months too.
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.