user3094896
user3094896

Reputation: 195

date format in AS3

I want my AS3 code to retrieve a specific date in MYSQL table.

I've got a format problem. When I write, in my AS3 code :

memberCombo.addItem( {label: "2015-06-23" } );
memberCombo.addEventListener(Event.CHANGE, checkComplete);

function checkComplete(evt:Event):void {

    var myVariables:URLVariables = new URLVariables();
        myVariables.username = evt.target.value;
        var myRequest:URLRequest = new URLRequest("http://www.***.com/sql_date.php");

    myRequest.method = URLRequestMethod.POST;
    myRequest.data = myVariables;
    trace(myRequest.data);

the trace(myRequest.data); result 2015%2D06%2D23 so it seems that it searching this 2015%2D06%2D23 in my SQL table (so it doesn't find it as the dates format in my table is YY-M-D).

Do you know how I can tell my AS3 code to look for the date in my SQL table in this format : YY-M-D ?

Thanks


EDIT

Here's what I did (but I made a mistake as it generate an error) :

    var myRequest:URLRequest = new URLRequest("http://www.****.com/sql_result.php");

myRequest.method = URLRequestMethod.POST;

    myRequest.data = myVariables;
    var myAS3Date;
    var myRequestString = "";
    myRequestString=dtAS3toMysql(myAS3Date);

function dtAS3toMysql( date:Date ):String {
    var s:String = date.fullYear + '-';

    // add the month
    if( date.month < 10 ) {
        s += '0' + ( date.month + 1 ) + '-';
    } else {
        s += ( date.month + 1 ) + '-';
    }

    // add the day
    if( date.date < 10 ) {
        s += '0' + date.date;
    } else {
        s += date.date;
    }

    return s;
}

Upvotes: 2

Views: 313

Answers (1)

Drew
Drew

Reputation: 24960

public static function dtMysql2AS3( s:String ):Date {
        var a:Array = s.split( '-' );
        return new Date( a[0], a[1] - 1, a[2] );
    }


public static function dtAS3toMysql( date:Date ):String {
    var s:String = date.fullYear + '-';

    // add the month
    if( date.month < 10 ) {
        s += '0' + ( date.month + 1 ) + '-';
    } else {
        s += ( date.month + 1 ) + '-';
    }

    // add the day
    if( date.date < 10 ) {
        s += '0' + date.date;
    } else {
        s += date.date;
    }

    return s;
}

Upvotes: 1

Related Questions