javascriptjqueryajaxjquery-plugins

jquery to convert date from mm/dd/yy to yyyy-dd-mm


I'm receiving an ajax response that has a date in the format mm/dd/yy. How can I convert this to the format yyyy-mm-dd using jquery? Does jquery have an internal function to do this?


Solution

  • Simple with no checking of the input (JavaScript, no jQuery):

    var d        = '01/25/90';   // as an example
    var yy       = d.substr(6,2);
    var newdate  = (yy < 90) ? '20' + yy : '19' + yy;
        newdate += '-' + d.substr(0,2) + '-' + d.substr(3,2); //1990-01-25