TIL Adds days to a date
POSTED ON:
TAGS: javascript dates
Maybe you just need some quick date math, and don't want to use a date library.
const addDaysToDate = (date, n) => {
date.setDate(date.getDate() + n);
return date.toISOString().split('T')[0];
};
addDaysToDate('2021-0-10', -10); // '2020-12-31'
REFERENCE:
21 Useful JavaScript Snippets For Everyday Development
Related TILs
Tagged: javascript