# How to get yesterday's date using JavaScript

> Learn how to get yesterday's date in JavaScript by taking today's Date and calling setDate() with getDate() minus 1, which even handles month boundaries.

Author: Flavio Copes | Published: 2019-10-10 | Canonical: https://flaviocopes.com/how-to-get-yesterday-date-javascript/

Well, first you get the date at the current time (today), then you subtract a day from it:

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

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

today.toDateString()
yesterday.toDateString()
```

We use the `setDate()` method on `yesterday`, passing as parameter the current day minus one.

Even if it's day 1 of the month, [JavaScript](https://flaviocopes.com/javascript/) is logical enough and it will point to the last day of the previous month.
