Manipulating Javascript Dates

today = new Date();
year = today.getFullYear();
month = today.getMonth();
day = today.getDate();
my_date = new Date(year, month, day - 23);

This will create a new date 23 days in the past. What is really useful is that you don’t have to do the additional math to calculate the date within a past month or year. Javascript will do it on its own. Likewise, any criteria for the new date will be automatically adjusted.

Related Post