tecdesign Posted June 16, 2006 Share Posted June 16, 2006 If you want to take a timestamp from a mysql database you must convert it into a unix timestamp to echo/print out a correct date. [code]$result=mysql_query ("SELECT UNIX_TIMESTAMP(mysql_column) as epoch_time FROM table"); $unix_timestamp = mysql_result ($result, 0, 0); echo date("F j, Y @ g:ia", $unix_timestamp);[/code]NB: This is an add on from the tutorial given here in the new snippet section. I just tried this code out and it works and it will solve alot of peoples problems, feel free to add it in as an extension. The as epoch_time is not neccessary for this situation as it is only renaming the column. Quote Link to comment https://forums.phpfreaks.com/topic/12142-datetime-mysql-to-php-solution/ Share on other sites More sharing options...
wildteen88 Posted June 16, 2006 Share Posted June 16, 2006 Or you can just use PHPs builtin function strtotime which converts the date into a unix timestamp, like so:[code]$result=mysql_query ("SELECT time_col FROM table");$row = mysql_fetch_array($result);$date = date("F j, Y @ g:ia", strtotime($row['time_col']));echo $date;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12142-datetime-mysql-to-php-solution/#findComment-46337 Share on other sites More sharing options...
tecdesign Posted June 16, 2006 Author Share Posted June 16, 2006 [!--quoteo(post=384636:date=Jun 16 2006, 04:22 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 16 2006, 04:22 AM) [snapback]384636[/snapback][/div][div class=\'quotemain\'][!--quotec--]Or you can just use PHPs builtin function strtotime which converts the date into a unix timestamp, like so:[code]$result=mysql_query ("SELECT time_col FROM table");$row = mysql_fetch_array($result);$date = date("F j, Y @ g:ia", strtotime($row['time_col']));echo $date;[/code][/quote]I've tried that and it doesn't seem to work for some reason... As it will just put the default date of 1970 or 1900 if you have php 5. My way seems to be successful in php 4.3.0 Quote Link to comment https://forums.phpfreaks.com/topic/12142-datetime-mysql-to-php-solution/#findComment-46463 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.