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