0

So I am currently fetching some records from my database, and one of the records is a 'last edited' which is a date. However, I just want to display this 10 days before it has been exactly one year since the specific date. How would I approach this? I know how to deal with arrays and the fetching itself, but I'm not sure how I would deal with the date?

This is what I've done so far:

var startDate = fetchedDate;
var validDate = new Date(startDate);
var fullYear = validDate.getFullYear();
validDate.setFullYear(fullYear + 1);

And then I need to create a new date to compare it, I suppose? But how? I also want to know how many days it is until it has been one year.

askaale
  • 1,199
  • 1
  • 23
  • 50

1 Answers1

0

If you wanna make it with pure javascript you can

var startDate = fetchedDate;
var validDate = new Date(startDate);
validDate.setYear(validDate.getFullYear() - 1);
validDate.setDate(validDate.getDate() - 10);

But I also will recommend you to use moment.js, is a very good javascript library to handle dates, otherwise sometimes is like trying to reinvent the wheel.

Miguel Angel
  • 944
  • 8
  • 20