Jump to content

Convert Timestamp to Date/Time in MySql Select statement


TecTao

Recommended Posts

I've been trying, researching and writing different snippets for 2 days to try and get a unix timestamp converted to a date/time.

 

Here is the select statement

 

  $q = "SELECT fname,email,timestamp "      ."FROM ".TBL_USERS." ORDER BY userlevel DESC,fname";  $result = $database->query($q);  /* Error occurred, return given name by default */  $num_rows = mysql_numrows($result);

 

Here is the

 

for($i=0; $i<$num_rows; $i++){      $fname  = mysql_result($result,$i,"fname");      $email  = mysql_result($result,$i,"email");      $time  = mysql_result($result,$i,"timestamp");

 

I have tried using a convert timestamp function, I've tried converting in the select statememt.

 

I most be missing something here, any ideas[/]

  • 3 weeks later...

Hi,

 

I was just researching the mysql method to do this when I came across this post.

 

MySQL method: selectfname, email, from_unixtime(timestamp) from your_table

From: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

 

PHP method: print date("Y-m-d h:i:s", $time);

 

HTH, Jochen

 

 

Archived

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

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