get the date for the first day of the current decade in typescript

Here's how to get the date for the first day of the current decade in Typescript using the date-fns library:

index.ts
import { startOfDecade } from 'date-fns';

const today = new Date();
const firstDayOfDecade = startOfDecade(today);

console.log(firstDayOfDecade); // Output: {Date Object for the first day of current decade}
209 chars
7 lines

Alternatively, you can use the moment.js library to achieve the same result:

index.ts
import moment from 'moment';

const today = moment();
const firstDayOfDecade = today.startOf('decade');

console.log(firstDayOfDecade); // Output: {Moment.js Object for the first day of current decade}
202 chars
7 lines

Both the date-fns and moment.js libraries provide easy-to-use functions for manipulating dates and times in JavaScript and TypeScript.

gistlibby LogSnag