hellonoko Posted December 28, 2007 Share Posted December 28, 2007 My below code to format the time in a DB echo's two different times. The first date being correct. the date is stored in the db as a DATETIME value. $query = "SELECT duedate FROM ideas WHERE id = '18'"; $result = mysql_query($query); $rows = mysql_fetch_array($result); $duedate = $rows[0]; echo $duedate; echo "<br>"; $duedate = date('F j Y H:i:s',$duedate); echo "<br>"; echo $duedate; exit(); Output: 2007-12-28 14:59:59 December 31 1969 16:33:27 Any reason why they are different? Am I using date() incorrectly? Thanks for your time, ian Link to comment https://forums.phpfreaks.com/topic/83450-solved-date-formating/ Share on other sites More sharing options...
corbin Posted December 28, 2007 Share Posted December 28, 2007 The date is being returned from sql to php as "2007-12-28 14:59:59" which to the date function means nothing. The date function takes an integer as its second paramenter, desired to be a unix time stamp. You can either pull the date from MySQL as a timestamp, or you can just do this: $query = "SELECT duedate FROM ideas WHERE id = '18'"; $result = mysql_query($query); $rows = mysql_fetch_array($result); $duedate = $rows[0]; echo $duedate; echo "<br>"; $duedate = date('F j Y H:i:s',strtotime($duedate)); echo "<br>"; echo $duedate; Link to comment https://forums.phpfreaks.com/topic/83450-solved-date-formating/#findComment-424548 Share on other sites More sharing options...
hellonoko Posted December 28, 2007 Author Share Posted December 28, 2007 Thanks, Im playing with the SELECT DATE_FORMAT mysql now. Link to comment https://forums.phpfreaks.com/topic/83450-solved-date-formating/#findComment-424550 Share on other sites More sharing options...
corbin Posted December 28, 2007 Share Posted December 28, 2007 No problem... I think there's a function like UNIX_TIMESTAMP or something, but I don't remember if that generates one or converts a field to a unix timestamp.... Link to comment https://forums.phpfreaks.com/topic/83450-solved-date-formating/#findComment-424555 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.