How to add N days to current date in JavaScript

1 Answer

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

function formatDate(date) {
    return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
}

const dt = formatDate(addDays(new Date(), 3));

console.log(dt);


  
    
    
/*
run:
    
"1/28/2021"
    
*/

 



answered Jan 25, 2021 by avibootz

Related questions

2 answers 153 views
1 answer 185 views
1 answer 140 views
1 answer 146 views
1 answer 204 views
1 answer 470 views
1 answer 193 views
...