Jump to content

Archived

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

tecdesign

datetime mysql to php solution

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

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.