Phpfr3ak Posted February 2, 2012 Share Posted February 2, 2012 I've been looking at converting my php timestamps to display as month, day, and the hour and minute the event occurred on, i tried; $time = date("j/n H:i", $Events['timestamp']); But no success can anyone point me in the correct direction? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/ Share on other sites More sharing options...
Pikachu2000 Posted February 2, 2012 Share Posted February 2, 2012 What format are they stored in? Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/#findComment-1313577 Share on other sites More sharing options...
Phpfr3ak Posted February 2, 2012 Author Share Posted February 2, 2012 CURRENT_TIMESTAMP i.e 2012-02-02 04:00:04 Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/#findComment-1313578 Share on other sites More sharing options...
Pikachu2000 Posted February 2, 2012 Share Posted February 2, 2012 I find it preferable to use MySQL's DATE_FORMAT() function and have them formatted and ready to go. SELECT DATE_FORMAT(time_field, '%b %e, %H:%s') AS formatted_time FROM table With the field alias AS formatted_time, the formatted date/time would be available in the ['formatted_time'] element of your associative array. Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/#findComment-1313579 Share on other sites More sharing options...
Phpfr3ak Posted February 2, 2012 Author Share Posted February 2, 2012 $sql = "SELECT DATE_FORMAT(timestamp, '%b %e, %H:%s') AS formatted_time FROM ledger"; $que = mysql_query($sql) or die(mysql_error()); echo "<tr><td class='lil1'>$que[formatted_time]</td>"; would that be correct? sorry thinking i maybe read it wrong Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/#findComment-1313582 Share on other sites More sharing options...
scootstah Posted February 2, 2012 Share Posted February 2, 2012 For the record, you can either pass the value to strtotime() to get a unix timestamp or use MySQL's UNIX_TIMESTAMP() function. SELECT UNIX_TIMESTAMP(date) . . . Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/#findComment-1313584 Share on other sites More sharing options...
Pikachu2000 Posted February 2, 2012 Share Posted February 2, 2012 You still need to extract the results from the query resource with mysql_fetch_assoc(), and assuming you're expecting more than one result, it would be in this format: $sql = "SELECT DATE_FORMAT(timestamp, '%b %e, %H:%s') AS formatted_time FROM ledger"; $que = mysql_query($sql) or die(mysql_error()); while( $array = mysql_fetch_assoc($que) ) { echo "<tr><td class='lil1'>$array[formatted_time]</td>"; } Quote Link to comment https://forums.phpfreaks.com/topic/256230-php-timestamp-conversion/#findComment-1313585 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.