I have to calculate the difference between two selected dates. The day start is considered 12am and the day end is the next 12am.
Javascript code:
const date1 = new Date('2019-06-12T10:30:00Z');
const date2 = new Date('2019-06-14T10:30:00Z');
const diffTime = Math.abs(date2.getTime() - date1.getTime());
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffDays);
I get the difference as 2 days which is not what I want, as day is calculated from 12am. The actual answer should be 3 days. What needs to be changed in the code to get the output 3 days? i.e.
1) First Day : 12 June 10:30am - 13 June 12:00am
2) Second Day : 13 June 12:00am - 14 June 12:00am
3) Third Day : 14 June 12:00am - 14 June 10.30am
Any help would be appreciated.. Thanks!