Displaying date from SQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Displaying date from SQL database

Post by mjseaden »

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
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<?php
$date = explode("-", "YYYY-MM-DD");
list($year, $month, $day) = $date;
echo "$day-$month-$year";
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Personally, I'd ask MySQL to return a UNIX_TIMESTAMP or reformat it using stuff from: Date and Time functions
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

you can do php or you could let MYSQL format it for you.

Code: Select all

SELECT DATE_FORMAT(my_date_field, "%d-%m-%Y") AS format_date FROM table;
http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html
Post Reply