How To Add Days To JavaScript Date With date-fns
// import isn't supported in Node v18.11.0 otherwise it would be
// import { addDays } from 'date-fns'
const dateFns = require( "date-fns");
const {addDays} = dateFns;
// 4th of July 2023
const date = new Date(2023, 6, 4);
console.dir(date);
console.log('Add 3 days: ', addDays(date, 3));
console.log('Add 7 days: ', addDays(date, 7));
console.log('Add 31 days: ', addDays(date, 31));
no comments