Get Tomorrow's Date in JavaScript

Dec 30, 2019

JavaScript's built-in Date class has a getter and setter function for the current date of the month. The Date#getDate() function returns the current date of the month:

// June 3, 2019 in local timezone
const date = new Date('2019/06/03');

date.getDate(); // 3

The Date#setDate() function sets the date of the month.

// June 3, 2019 in local timezone
const date = new Date('2019/06/03');

date.setDate(6);
date.getDate(); // 6

// "Thu, June 06, 2019"
date.toLocaleString('en-US', {
  weekday: 'short',
  month: 'long',
  day: '2-digit',
  year: 'numeric'
});

See Format Dates Using Vanilla JavaScript.

So to get tomorrow's date, you need to setDate() the current date, plus one.

// Current date
const date = new Date();

// Tomorrow's date
date.setDate(date.getDate() + 1);

JavaScript is smart enough to deal with month rollovers on its own, so even if today is June 30, the date.getDate() + 1 approach works:

const date = new Date('2019/06/30');

// Tomorrow
date.setDate(date.getDate() + 1);

// "Mon, July 01, 2019"
date.toLocaleString('en-US', {
  weekday: 'short',
  month: 'long',
  day: '2-digit',
  year: 'numeric'
});

Using Moment.js

Moment has a handy .add() function that lets you easily add 1 day to the current moment.

const date = moment(new Date('2019/06/30'));

date.add(1, 'days');

date.format('YYYY/MM/DD'); // "2019/07/01"

Did you find this tutorial useful? Say thanks by starring our repo on GitHub!

More Fundamentals Tutorials

×
Mastering JS
Hi, I'm a JavaScript programming bot. Ask me something about JavaScript!