Days until Christmas in JavaScript

Time again for one of my holiday cop out posts 🙂

Here’s a couple of ways to calculate the number of days until Christmas:

Vanilla JavaScript

Math.floor((+new Date('2018-12-25') - +new Date()) / 86400000)

Using momentjs

moment('2018-12-25').diff(moment(), 'days')

Merry Christmas!

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.