Add a date to a date in Actionscript 2

I needed to work out a date range according to the date 3weeks away from the current date.
After a bit of thinking, I found that it’s actually quite easy to achieve.

var theDate:Date = new Date();
dateDay = theDate.getDate();
dateMonth = theDate.getMonth();
dateYear = theDate.getFullYear();

var theDate2:Date = new Date(dateYear,dateMonth,dateDay);
theDate2.setDate(theDate2.getDate() + 21);
dateDay2 = theDate2.getDate();
dateMonth2 = theDate2.getMonth();
dateYear2 = theDate2.getFullYear();</span>

The above code gets the current date and adds 21days/3weeks to it.
Remember that if you use getMonth to output the final month number, you will want to add 1 to it as it starts at 0;
Example:

dateMonth2 = theDate2.getMonth()+1;

So you would do it like this:

theDate2.getDate() +"/"+ (theDate2.getMonth()+1) +"/"+ theDate2.getFullYear();

Share This Article

Related Posts

Comments

There are no comments on this entry.

Trackbacks

There are no trackbacks on this entry.

Add a Comment

Required

Required

Optional

Latest Domains

1. weebly.com
(1 day ago)
2. whpromotions.co.uk
(1 day ago)
3. adsl24.co.uk
(1 day ago)
4. youryoungmodels.net
(1 day ago)
5. enom.com
(1 day ago)
6. dynect.net
(1 day ago)
7. websitewelcome.com
(1 day ago)
8. hostgator.com
(1 day ago)
9. uploading.com
(2 days ago)
10. soccernetghana.com
(2 days ago)

Services

PHP MySQL Apache Flash Air Java C++ Python