get the date 5 days ago in typescript

To get the date 5 days ago in TypeScript, you can use the Moment.js library. Here is an example using Moment.js:

index.ts
import moment from 'moment';

const date = moment().subtract(5, 'days').toDate();
console.log(date);
101 chars
5 lines

In this example, we first import the Moment.js library. Then we use the moment() function with no arguments to get the current date and time. We then use the subtract() function to subtract 5 days from the current date. Finally, we use the toDate() function to convert the result to a JavaScript Date object. The console.log(date) statement will output the date 5 days ago in the console.

related categories

gistlibby LogSnag