Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Increment a Date in JavaScript Without Using Any Libraries



To add one day to date in JS, the setDate function is the best way. You can create the following function on the Date prototype to add days to the date.

Example

Date.prototype.addDays = function(days) {
   let d = new Date(this.valueOf());
   d.setDate(d.getDate() + days);
   return d;
}
let date = new Date();
console.log(date.addDays(1));

This will log the next day.

Updated on: 2019-11-27T10:41:22+05:30

151 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements