get the date 5 years ago in javascript

To get the date 5 years ago in JavaScript, you can subtract 5 years from the current date. Here's a code snippet that does this:

index.tsx
var currentDate = new Date();
var fiveYearsAgo = new Date(currentDate.getFullYear() - 5, currentDate.getMonth(), currentDate.getDate());
137 chars
3 lines

This code creates a new Date object for the current date, and then subtracts 5 years from the year using the getFullYear() method. The resulting date object represents the date that was 5 years ago from today.

gistlibby LogSnag