How to format a DateTime MySql Field ?

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
tintin
Forum Newbie
Posts: 13
Joined: Fri Dec 13, 2002 7:13 am

How to format a DateTime MySql Field ?

Post by tintin »

Hi,

After having fetched a TimeStamp field, I can perform some computations and display it with something like : date ( $format, $row[0] );

But I can't find how to do the same with a DateTime. Should I convert it before and how ?

I would like to avoid the workaround to select from the database both the value, and the Mysql formatted value.

Thanks for help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

MySQL has some handy Date and Time functions:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

For formatting for display I tend to use DATE_FORMAT(), if, however, I'm going to need to manipulate the date once it's been extracted then UNIX_TIMESTAMP() comes in handy.

Mac
Post Reply