Add days to Date in ActionScript

Lea Cohen picture Lea Cohen · Sep 15, 2009 · Viewed 22.3k times · Source

We have an application in which the user has to enter a date who's value is no more than 30 days after the the current date (the date on which the user uses the application). This is a Flash application, therefore I need a way to add 30 days to the current date, and get the right date. Something like in JavaScript:

myDate.setDate(myDate.getDate()+30);

Or in C#:

DateTime.Now.Add(30);

Is there such a thing in ActionScript?

Answer

Ryan Guill picture Ryan Guill · Sep 15, 2009

While the other answers will work im sure, it is as easy as doing:

var dte:Date = new Date();
dte.date += 30; 
//the date property is the day of the month, so on Sept. 15 2009 it will be 15

This will even increment the month if necessary and year as well. You can do this with the month and year properties as well.