Enter your email address:

    Delivered by FeedBurner

Saturday, March 07, 2009

Actionscript: Add One Day to Date

The script below is a sample on how to add one day to a date.

private function buttonClick():void {
// text is a date with format 'mm/dd/yyyy'
dtsTranDate.text = addDate(dtsTranDate.text);
}


private function addDate(dt:String):String {
var arrDate:Array = (dt).split('/');
var m:int = int(arrDate[0]); // month
var d:int = int(arrDate[1]); // day
var y:int = int(arrDate[2]); // year
var lastday:int;

// get last day of the month
var dd:Date = new Date(y, m, 0);
lastday = dd.getDate();

d = d + 1;

if (d > lastday) {
d = 1;

if (m < 12) {
m = m + 1;
}
else {
m = 1;
y = y + 1;
}
}

var newdate:String;
newdate = ((m < 10)?('0'+m.toString()):m.toString()) + '/' + ((d < 10)?('0'+d.toString()):d.toString()) + '/' + y.toString();

return newdate;
}



I would like to thank Molaro for the script on getting the last day of the month.



=)

0 comments:

Post a Comment

About Me

My photo
I provide health supplements, adult wellness products, glutathione, and other merchandise. Please visit my online shop at: http://luckycowshop.blogspot.com/