How To Add Weeks to a Date in JavaScript with date-fns

node v18.11.0
version: 1.0.0
endpointsharetweet
// import isn't supported in Node v18.11.0 otherwise it would be // import { addWeeks } from 'date-fns' const dateFns = require( "date-fns"); const { addWeeks } = dateFns; // 31th of January 2023 const date = new Date(2023, 0, 31); console.log(date); console.log('Add 1 week: ', addWeeks(date, 1)); console.log('Add 3 weeks: ', addWeeks(date, 3)); console.log('Add 9 weeks: ', addWeeks(date, 9));
Loading…

no comments

    sign in to comment