Add Day To Date Javascript Code Example


Example 1: js date add 1 day

let date = new Date(); // add a day date.setDate(date.getDate() + 1);

Example 2: javascript add day to date

function addDays(date, days) {   var result = new Date(date);   result.setDate(result.getDate() + days);   return result; }

Example 3: javascript add days to date

var myCurrentDate=new Date(); var myFutureDate=new Date(myCurrentDate);     myFutureDate.setDate(myFutureDate.getDate()+ 8);//myFutureDate is now 8 days in the future

Example 4: javascript date add days

function addDays(originalDate, days){   cloneDate = new Date(originalDate.valueOf());   cloneDate.setDate(cloneDate.getDate() + days);   return cloneDate; }  let appointment = new Date("February 12, 2021 00:00:00"); let newAppointment = addDays(appointment, 7);  console.log(appointment.getDate()); // 12 console.log(newAppointment.getDate()); // 19

Example 5: javascript add days

Date.prototype.addDays = function(days) {     var date = new Date(this.valueOf());     date.setDate(date.getDate() + days);     return date; }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable