Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/12142-datetime-mysql-to-php-solution/
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]
[!--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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.