How can i change the format of my date?

Here's a sample of my code:

$q = @mysql_query("SELECT * FROM products WHERE id='$id'");
$r = mysql_fetch_array($q);
$created = $r['created'];
echo "$created";

This will display the date in the US format, yyyy/mm/dd. I want it to be displayed in the european format, dd/mm/yyyy.

    Ex:

    SELECT DATE_FORMAT(date_field, '%d/%m/%Y' ) FROM table;

    Check out DATE_FORMAT() for more info.

    If you want to do an order by on the same field you use in the SELECT it can by handy to write the sql like this

    SELECT DATE_FORMAT(date_field_1,'%d/%m/%Y') FROM table ORDER BY DATE_FORMAT(date_field_1,'%Y-%m-%d');

    since in my experience if you dont the order by field will be in the format of %d/%m/%Y (or whatever you set it in the SELECT part).

      is there a way to do it with php, not in the mysql_query?

        You could always check out http://www.w3schools.com/php/php_ref_date.asp or http://php.net/manual/en/ref.datetime.php for php date functions.

        Edit: Date() could be what you want

        echo date('d/m/Y',mktime(0,0,0,6,20,2007)); // displays 20/6/2007
        echo date('d/m/Y'); //displays todays date 11/6/2007

        You could do something like this

        $row=mysql_fetch_assoc(mysql_query("SELECT * FROM something WHERE id=1"));
        //presume date format YYYY-MM-DD
        //either this way
        $year=substr($row['date'],0,4);
        $month=substr($row['date'],5,2);
        $day=substr($row['date'],8,2);
        echo date('d/m/Y',mktime(0,0,0,$month,$day,$year));
        // or 
        echo date('d/m/Y',mktime(0,0,0,substr($row['date'],5,2),substr($row['date'],8,2)y,substr($row['date'],0,4));
        

          try this also

          
          $date = $row["date"];
          //$date = '2006-09-11';  // Assume this came from your database
          $ts = mktime(0,0,0,substr($date,5,2),substr($date,8,2),substr($date,0,4));
          $formated = date('d-m-Y',$ts);
          }

          Converts to unix format = '11-09-2006'

            Write a Reply...