DEV Community

Cover image for Find the days between the two timestamps
Dezina
Dezina

Posted on

Find the days between the two timestamps

startDate = 2021-12-20T06:30:00.000Z
endDate = 2022-01-10T07:30:00.000Z

var date1 = moment(startDate).format('DD/MM/YYYY')
var date2 = moment(endDate).format('DD/MM/YYYY')
const date3 = new Date(date1.split('/')[2],date1.split('/')[1]-1,date1.split('/')[0])
const date4 = new Date(date2.split('/')[2],date2.split('/')[1]-1,date2.split('/')[0])
var timeDiff = Math.abs(date4.getTime() - date3.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log("diffDays", diffDays)

Top comments (0)