How to change YYYY-MM-DD to DD-MM-YYYY in mysql

Discussion in 'Programming' started by Kurt Whittingham, May 13, 2012.

  1. #1
    ive searched google, and from what i read it said to add code into the php so i tried but everything failed.

    this is what i am using at the moment without the change for the dd-mm-yyyy in it

     $result = mysql_query("SELECT * FROM articles WHERE category_id='1' ORDER BY article_id DESC ")
    PHP:
    if anyone could help thanks :)
     
    Kurt Whittingham, May 13, 2012 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    The format of MySQL DATE and DATETIME fields is fixed and you can't change it. You could use DD-MM-YYYY if you change the field type to TEXT or other general formats. But it's generally best to use the conventional DATE type and extract the data in your scripts as needed. It isn't difficult.
    
    list($year, $month, $day) = explode('-', $dateFieldContents);
    
    Code (markup):
     
    rainborick, May 13, 2012 IP