Showing date as different 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
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Showing date as different format?

Post by tomsace »

Hello,
When a user registeres to my website it saves the date they joined in the format yyyy-mm-dd
How can I display the date they joined as dd mm yyyy (22nd march 2009 for example)

Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Showing date as different format?

Post by requinix »

If you stored the date in the database as YYYY-MM-DD then use MySQL's DATE_FORMAT function.

Code: Select all

SELECT ...DATE_FORMAT(field, "%D %M %Y")...
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: Showing date as different format?

Post by tomsace »

thanks! but how do I change it from say 1 may 2009 to 1st may 2009?
kalebaustin
Forum Newbie
Posts: 12
Joined: Mon Nov 19, 2007 11:28 am

Re: Showing date as different format?

Post by kalebaustin »

DATE_FORMAT(field, "%D %M %Y") will return (for today) 6th June 2009

the %D = Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)



Source: http://dev.mysql.com/doc/refman/5.1/en/ ... ate-format
Post Reply