Categories

Saturday, October 16, 2021
therichposts@gmail.com
HtmlJquery

How to get month difference between two dates?

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to get month difference between two dates?

I like jQuery the most and in my all the project, I do my all the things done with jquery.

In this post, I will tell and How to get month difference between two dates? with help of jquery.

Here is the working code snippet and you can add this code into your HTML file easily:

Old Date(2019 january): <span class="OldDate">2/10/2019</span>
Today(september month 2019): <span class="Todaydate">9/10/2019</span>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
 jQuery(document).ready(function($)
 {
   var OldDate = $(".OldDate").text();
   var Newdate = $(".Todaydate").text();
   var oldD = new Date(OldDate);
   var newD = new Date(Newdate);
   //This alert will show you months diffrence
   alert((newD.getMonth()+1)-(oldD.getMonth()+1)); 
 })
</script>

 

This is just demo working code and you can modify it with your own requirement.

Jassa Jatt.

Thank you

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.