Date format conversion

Discussion in 'PHP' started by Tintumol, Feb 27, 2011.

  1. #1
    I'm trying to make it so that if a date is entered in a certain format its converted to the format compatible with mysql.

    So far i have it able to convert the following formats

    YYYY-MM-DD
    YYYY/MM/DD
    DD-MM-YYYY
    DD/MM/YYYY
    YY-MM-DD

    I'm struggling to get it to convert

    DD-MM-YY

    Can anyone help. The code i have so far is

     
    Tintumol, Feb 27, 2011 IP
  2. xtmx

    xtmx Active Member

    Messages:
    359
    Likes Received:
    12
    Best Answers:
    4
    Trophy Points:
    88
    #2
    function date_convert($var)
    {
    
    list($day, $month, $year) = explode("/", $var);
    
    return implode("-", array($year, $month, $day));
    }
    PHP:
    Enjoy!
     
    xtmx, Feb 27, 2011 IP