Page 1 of 1

Problems with date function

Posted: Mon Apr 21, 2003 8:27 am
by nmotion
I have a date formated as follows:

2003-05-25

I want to be able to use the various formatting options I have with date()

How to I convert the date to a UNIX timestamp so I can do this. Or is this the wrong approach ? Any help will help :wink:

Posted: Mon Apr 21, 2003 9:39 am
by twigletmac
Is the date coming from a database or is it from elsewhere within your script?

Mac

From a MySql database.

Posted: Mon Apr 21, 2003 9:41 am
by nmotion
From a MySql database.

Posted: Mon Apr 21, 2003 9:49 am
by twigletmac
Then you can let MySQL do the date formatting in the SQL statement - DATE_FORMAT() works in a very similar way to date():

Code: Select all

SELECT DATE_FORMAT(date_field, '%d/%m%Y') AS date FROM table
to get a date in dd/mm/yyyy format.

Check out:
http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1303

Mac