[thelist] PHP/MySQL Date Format Help

Liam Delahunty liam at megaproducts.co.uk
Wed Aug 4 10:03:21 CDT 2004

on 04/08/2004 14:28 Rob Smith said the following:
> Hi,
> In this particular case, my date is 2004-08-01 (Last Sunday) that was
> entered by the "admin" for the purposes of placing into the mySQL database
> accurately. 
> I want to transform this date into a "readable" format for the end user.

> Can anyone offer a more cleaver way to reformat the YYYY-MM-DD into
> DD-MM-YYYY. Strangely enough I think I see the answer:

Is this getting data OUT of MySQL?

select date_format(date_field, '%d-%m-%Y') FROM table_name_tbl;

Just tried it on one of mine (field type of datetime):

mysql> SELECT date_format(date_ordered, '%d-%m-%Y') as date FROM 
orders_contact_tbl LIMIT 1;

| date       |
| 27-08-2003 |

1 row in set (0.00 sec)

Thinks it's got to be better to let MySQL do the work seeing as it's 
already getting the data, rather than throwing it to PHP too.

Kind regards, Liam Delahunty, Mega Products Ltd
12 Bury Place, London WC1A 2JL Fax: +44(0)871 224 7891
http://www.megaproducts.co.uk/ Internet Design & Development

More information about the thelist mailing list