Javascript -Nodejs get yesterday, today tomorrow date

Rojan Dhimal
Mar 31, 2022

In this article, you will find how to get today, tomorrow, yesterday date, and any date you want. Here I will also show how to set time in the new date object.

Javascript date

Follow the code below.

To get new date or today's date
let today = new Date() // this returns current date time
to set time
today.setHours(12,0,0,0); // this will set today date variable to 12 PM
today.setHours(0,0,0,0)
let yesterday = new Date(today)
yesterday.setDate(yesterday.getDate() - 1) // this will subtract 1d
yesterday.setHours(0,0,0,0) // set yesterday time to 00 AMlet tomorrow = new Date() // initialize today// set today to 24 hr this will make tomorrow date
tomorrow.setHours(24,0,0,0)

Thank you for reading, have a productive day.

--

--