Skip to content

Instantly share code, notes, and snippets.

@jjbel
Created April 17, 2023 17:39
Show Gist options
  • Save jjbel/94589398970bdae2ea090448b9861a47 to your computer and use it in GitHub Desktop.
Save jjbel/94589398970bdae2ea090448b9861a47 to your computer and use it in GitHub Desktop.
Add days to a Date
function addDays(input_date, days) {
let date = new Date(input_date);
date.setDate(date.getDate() + days);
return date;
}
function formatDate(date) {
const day = date.toLocaleString('default', { day: '2-digit' });
const month = date.toLocaleString('default', { month: 'short' });
const year = date.toLocaleString('default', { year: 'numeric' });
return day + '-' + month + '-' + year;
}
let date1 = new Date('16-Feb-2023');
let date2 = addDays(date1, 3);
console.log(formatDate(date2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment