Problems with date function

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
nmotion
Forum Commoner
Posts: 32
Joined: Wed Jan 22, 2003 6:53 am

Problems with date function

Post 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:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Is the date coming from a database or is it from elsewhere within your script?

Mac
nmotion
Forum Commoner
Posts: 32
Joined: Wed Jan 22, 2003 6:53 am

From a MySql database.

Post by nmotion »

From a MySql database.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply