-1

I am wondering if there is a way to get the date for example 63 days prior? Only day, month and year is required, no hours, minutes and seconds.

I know that it is possible to do Date object - Date object but I wondering if it is possible to date Date object (Date.now()) - an int (63),

Contentop
  • 1,163
  • 3
  • 20
  • 43

1 Answers1

1

Kip has left a thorough answer in How to add 30 minutes to a JavaScript Date object?.

You can do this to add or subtract days from a date by entering diff as a positive or negative number:

var newDateObj = new Date(oldDateObj.getTime() + diff*24*60*60000);

The 24*60*60000 stands for 24 hours * 60 minutes * 60 seconds to multiplies to the total milliseconds in a day.

Typically you do not want to do this because dates are complicated. Kip mentions that if a user is observing Daylight Savings, days deviate from 24 hours which will mess up your calculation.