Dear All,
I have a date stored in a MySQL database which I am simply 'echoing' to display on my webpage. However, when I echo is, it displays in YYYY-MM-DD format, whereas I want it displayed in DD-MM-YYYY format, or even '23rd March 2004' format.
Can anyone tell me if it's a MySQL query syntax I need to use or a PHP function acting on the date?
Many thanks
Mark
Displaying date from SQL database
Moderator: General Moderators
Code: Select all
<?php
$date = explode("-", "YYYY-MM-DD");
list($year, $month, $day) = $date;
echo "$day-$month-$year";
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Personally, I'd ask MySQL to return a UNIX_TIMESTAMP or reformat it using stuff from: Date and Time functions
you can do php or you could let MYSQL format it for you.
http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html
Code: Select all
SELECT DATE_FORMAT(my_date_field, "%d-%m-%Y") AS format_date FROM table;