Created
April 17, 2023 17:39
-
-
Save jjbel/94589398970bdae2ea090448b9861a47 to your computer and use it in GitHub Desktop.
Add days to a Date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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