Add a date to a date in Actionscript 2

0 min read 116 words

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();

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();

Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags