Skip to content

Find the number of days between two days using JavaScript

Advertisements

Find the number of days between two days using JavaScript with this code snippet.

const dayDiff = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000)

dayDiff(new Date("2020-11-21"), new Date("2021-10-22"))
// Result: 30
See also  What are the possible ways to create objects in JavaScript?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.