86Stang Posted February 1, 2008 Share Posted February 1, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/88857-formating-a-variable-that-holds-a-timestamp/ Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 Search the forums for strtotime Quote Link to comment https://forums.phpfreaks.com/topic/88857-formating-a-variable-that-holds-a-timestamp/#findComment-455112 Share on other sites More sharing options...
sasa Posted February 1, 2008 Share Posted February 1, 2008 try <?php $a = '2008-01-21 03:14:47'; echo $t = date('F d<\sup>S</\sup>, Y.', strtotime($a)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88857-formating-a-variable-that-holds-a-timestamp/#findComment-455114 Share on other sites More sharing options...
haku Posted February 1, 2008 Share Posted February 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88857-formating-a-variable-that-holds-a-timestamp/#findComment-455231 Share on other sites More sharing options...
harristweed Posted February 1, 2008 Share Posted February 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88857-formating-a-variable-that-holds-a-timestamp/#findComment-455238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.