-3

Here two date variable available.one is date and another one is todaydate.

I need to calculate the day in between today date and date.

var s=jSonArray[0].new_StartDate;//retrive the s value from Json Array 
var dateString = s.substr(6);
var currentTime = new Date(parseInt(dateString ));
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();

var date = month  + "/" +day  + "/" + year;

 var currentDateTime = new Date();
 var todaydate= (currentDateTime.getMonth() + 1) + '/' + currentDateTime.getDate() + '/' +  currentDateTime.getFullYear();
User
  • 1,644
  • 10
  • 40
  • 64
  • Refer to this link: http://stackoverflow.com/questions/26956723/calculate-date-difference-in-javascript/26956927#26956927 – Pankaj Goyal Nov 27 '14 at 11:36

2 Answers2

0

refer to these links.

Get difference between 2 dates in javascript?

How do I get the number of days between two dates in JavaScript?

Community
  • 1
  • 1
IMRUP
  • 1,463
  • 2
  • 11
  • 17
0

function takes two dates and returns the number of days between the first and second dates.

function getDays(a,b){
var Time=b.getTime()-a.getTime();
var diff=Time/(1000*60*60*24);
console.log(diff);

 }

 getDays(
new Date("June 14, 2019"),
new Date("June 20, 2019")
)
/*another way*/
function getDays(a,b){
var dateOne=new Date(a),
dateTow=new Date(b);

var Time=dateTow.getTime()-dateOne.getTime();
var diff=Time/(1000*60*60*24);
console.log(diff);

}
getDays("July 20, 2019","July 30, 2019");