change data time format

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
theclay7
Forum Commoner
Posts: 50
Joined: Wed Feb 19, 2003 3:17 am

change data time format

Post by theclay7 »

when I retrieve my date and time from database and display as follow:

2003-03-14 14:42:18

How can I easily change the format into :

Mar 14th, 2003, 2:42pm
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you're using MySQL:

Code: Select all

SELECT DATE_FORMAT(datefield, '%b %D, %Y, %l:%i%p') AS date FROM table
For more info on DATE_FORMAT:
http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1298

Mac
Post Reply