How to Get Yesterday’s Date With JavaScript

To get yesterday’s date with JavaScript, you simply need to get the current date, and then subtract one day from it, like this:

const today = new Date()
const yesterday = new Date(today)

yesterday.setDate(yesterday.getDate() - 1)

today.toDateString()
yesterday.toDateString()

Now try console logging out yesterdays date:

console.log(yesterday.toDateString())

Nice and simple!


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on