How to calculate difference of seconds, hours, weeks, months, years with jquery between two days?

QuestionsCategory: QuestionsHow to calculate difference of seconds, hours, weeks, months, years with jquery between two days?
lovedeep asked 2 years ago

How to calculate diffrence of seconds, hours, weeks, months, years with jquery between two days?

2 Answers
Best Answer
therichpost answered 2 years ago

Here is code for all:
 
       /*Diffrence in Years*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var years          = diff/1000/60/60/24/365;
      var DailyDaysDiff = Math.round(years);
 
       /*Diffrence in Months*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var months          = diff/1000/60/60/24/30.4375;
      var DailyDaysDiff = Math.round(months);
 
 
      /*Diffrence in Weeks*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var weeks          = diff/1000/60/60/24/30.4375;
      var DailyDaysDiff = Math.round(weeks);
 
 
      /*Diffrence in Days*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var days          = diff/1000/60/60/24;
      var DailyDaysDiff = Math.round(days);
 
       /*Diffrence in Hours*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var Hours          = diff/1000/60/60;
      var DailyDaysDiff = Math.round(Hours);
 
       /*Diffrence in Minutes*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var Minutes          = diff/1000/60;
      var DailyDaysDiff = Math.round(Minutes);
 
      /*Diffrence in Seconds*/
var end           = new Date($(“#endMonthlyDate”).val());
      var start         = new Date();
      var diff          = new Date(end – start);
      var Seconds          = diff/1000;
      var DailyDaysDiff = Math.round(Seconds);