How To Subtract Weeks from a Date in JavaScript with date-fns
// 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));
no comments