0
votes

In several different moments, I need to convert dates from dd/mm/yyyy to mm/dd/yyyy.

I get the data formated like dd/mm/yyyy from a database.

So, I'd like to know how to use the same formula from different functions. For example in a function I do this:

function getMDY (){
    var month = theDay.substr(3,2);
    var day = theDay.substr(0,2);
    var year = theDay.substr(6,4);
    var theDate = month + "/" + day + "/" + year;
    trace (theDate);
}

I want to call this function from other functions giving theDay value, and receiving back the value of theDate.

I don't know how to do this. Any clue?

Thanks.

1

1 Answers

3
votes

getMDY() needs an input argument and a return value:

function getMDY(inputDate:String):String
{
    var n:Array = inputDate.split('/');
    return [n[1],n[0],n[2]].join('/');
}

Usage:

trace( getMDY("30/08/1991") ); // 08/30/1991