Jump to content

Formating a variable that holds a timestamp


86Stang

Recommended Posts

I used the timestamp type to capture the date/time of when a record was created.  I would like to display that timestamp but in a different format.  In the database it displays as 2008-01-25 03:14:47 but I'd like to display it as January 25, 2008.  Anybody got a clue on how to do this?

Its good practice to always store dates in your database as unix timestamps, and to convert them when they come out. Unix timestamps can be formatted pretty much anyway you want, so they are very versatile. Check out date(): http://jp2.php.net/date to find out more.

 

If you need to convert a date into a unix timestamp when you put it in your database, you can use mktime(): http://jp2.php.net/mktime

You can use inbuilt mysql functions to extract timestamp dates in different formats:

 

select  date_format('your field name', ' %M %e, %Y')  AS readable_date........WHERE....

 

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.