Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

How To Subtract Weeks from 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 { subWeeks } from 'date-fns' const dateFns = require( "date-fns"); const { subWeeks } = dateFns; // 31th of January 2023 const date = new Date(2023, 0, 31); console.log(date); console.log('Subtract 1 week: ', subWeeks(date, 1)); console.log('Subtract 3 weeks: ', subWeeks(date, 3)); console.log('Subtract 9 weeks: ', subWeeks(date, 9)); console.log('Subtract 52 weeks: ', subWeeks(date, 52));
Loading…

no comments

    sign in to comment