Get Tomorrow’s Date using JavaScript – Quick Way

featured Image

Lets see how to get tomorrow’s date in JavaScript or by using a open-source library like momentjs.

Read about : How to get Yesterday’s date in JavaScript

In JavaScript, to get tomorrow’s date we have to get the current date using new Date() method and then we have to add one day to it and it will give us the date of the next day.

Using new date() to get tomorrow’s date in JavaScript

const today = new Date()
const tomorrow = new Date(today)

tomorrow.setDate(tomorrow.getDate() + 1)
const tomorrowDate = tomorrow.toDateString()

console.log(tomorrowDate)

Output:

Fri Jan 07 2022

Code Explanation:

new Date() : Gives current date and time of the day.

getDate() : It extract the date of the month from the string of new Date().

tomorrow.getDate() + 1 : We extract the date (Eg today is 6 ) and then add 1 to it, so we get 7 (next day date).

setDate() : Allow us to change the day of the month. In the code above, we use setDate() to set the value to 7.

toDateString() : It returns the date in proper format in English.

Using JavaScript Library – momentJs

Momentjs is an open-source JavaScript library which remove the need to use the native JavaScript new Date() method.

Using momentJs, we can get the current date in a proper date format by:

moment().format("YYYY-MM-DD")

So to get tomorrow’s date using momentJs we have to add 1 as days :

moment().add(1, "days").format("YYYY-MM-DD");

Related Topics:

Get Current Date in Different Date Formats in JavaScript

Related Posts

featured Image

Get the 10 characters from a string using JavaScript.

Here, in this article we will learn how to get the first 10 character from any string using JavaScript. Here we will be using JavaScript’s String method substring. What is…

Read more
featured Image

Convert date to long date format using JavaScript

In this article we will look into how to convert a date to a long date format using JavaScript. To convert it to a long format we will be using…

Read more
featured Image

Prevent body from scrolling when a modal is opened

Here, in this article, we will learn how to prevent the body from scrolling when a modal or a pop-up is opened using JavaScript. The scroll event is not cancelable….

Read more