add days to a date in javascript code example

Example 1: javascript add day to date

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

Example 2: javascript add 1 day to new date

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

Example 3: 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