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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay