0

I am try to get number of days between two dates. here is my code--

Var first = new Date('2021-09-01T03:24:00');
Var second = new Date('2022-09-02T05:24:00');
Var Difference = second.getdate() - first.getdate();
console.log('Difference day---->' + Difference);

Output:

Difference day---->1 day

But Correct Output:

Difference---->366 days

1 Answer 1

1

getDate only returns the "day" part of the date.

You'll want to do something like this:


var Difference_In_Time = date2.getTime() - date1.getTime();
  
                                    //Milliseconds * Seconds in a Hour * Hours in a Day
var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);

You must log in to answer this question.