find the date string of last 3 days in typescript

You can use moment.js library to find the date string of last 3 days in typescript. Here's the code using moment.js:

index.ts
import * as moment from 'moment';

const today = moment().format('YYYY-MM-DD');
const lastThreeDays = moment().subtract(3, 'days').format('YYYY-MM-DD');

console.log('Today:', today); // Today: 2022-03-14
console.log('Last 3 days:', lastThreeDays); // Last 3 days: 2022-03-11
276 chars
8 lines

In this code, we import moment library and use it to get today's date in the specified format. We then subtract 3 days from today's date using subtract method of moment. Finally, we get the date string of last 3 days in the specified format using format method of moment.

gistlibby LogSnag