
How can I find the difference between two dates in terms of months using javascript?

<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);
document.write("Date difference in month : "+monthDiff);
</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 and number of months by using getMonth() method .To get the date difference in months you must also consider years diffrence.
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.