How To Subtract Days 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 { 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);
Loading…

no comments

    sign in to comment