How to get yesterday’s, today’s, and tomorrow’s date using JavaScript

In this short article, we’ll explain to you how to get yesterday’s, today’s, and tomorrow’s date using Javascript. Using the Date object, we can easily calculate the date in JavaScript.

JavaScript has a built-in Date object that represents the current date and time. First, we will get the current date (Today) and then after we can get the date of yesterday and tomorrow.

Get yesterday’s, today’s, and tomorrow’s date using JavaScript

  1. Get today’s date
  2. Get yesterday’s date
  3. Get tomorrow’s date

1. Get today’s date

As we mentioned, we will get today’s date using the date object as shown below in the code. We will use the toDateString() method to convert the date into a readable string.

2. Get yesterday’s date

To calculate yesterday’s date, first we have to get the current date (today) then subtract 1 day from the date.

Here, we have used the getDate() function to get the day of the date. After subtracting one day from the date, use the setDate() function to set yesterday’s date into the date object.

3. Get tomorrow’s date

Same way, we can easily calculate the tomorrow’a date. Here, we add 1 day in the current date.

I hope you find this article is helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

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