DEV Community

CP
CP

Posted on • Edited on

Javascript Yesterday, Today, and Tomorrow

Simple day manipulation with Javascript (without using moments)

// Construct yesterday, today, tomorrow
const today = new Date();

const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);

const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);

console.log('Yesterday: ', yesterday.toDateString());
// => Yesterday:  Tue May 26 2020

console.log('Today: ', today.toDateString());
// => Today:  Wed May 27 2020

console.log('Tomorrow: ', tomorrow.toDateString());
// => Tomorrow:  Thu May 28 2020
Enter fullscreen mode Exit fullscreen mode

Top comments (0)