aebstract Posted March 31, 2008 Share Posted March 31, 2008 I have a unix timestamp such as: 1200435437 I need to convert this in to something like m/d/Y with the date function, how can I go about doing this? Thanks! Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/ Share on other sites More sharing options...
AndyB Posted March 31, 2008 Share Posted March 31, 2008 http://www.plus2net.com/php_tutorial/php_date_time.php Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506033 Share on other sites More sharing options...
discomatt Posted March 31, 2008 Share Posted March 31, 2008 check out date() echo date('m/d/Y', $stamp); Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506034 Share on other sites More sharing options...
aebstract Posted March 31, 2008 Author Share Posted March 31, 2008 $date_created_readable = date('m/d/Y', $date_created); echo "$date_created_readable"; That is what I have, but it is just displaying: 01/15/2008 for every value, but every row in the db has a different value for date_created. Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506037 Share on other sites More sharing options...
AndyB Posted March 31, 2008 Share Posted March 31, 2008 That is what I have, but it is just displaying: 01/15/2008 for every value, but every row in the db has a different value for date_created. Then there's a problem with how you're retrieving the data. show us some more complete code Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506041 Share on other sites More sharing options...
aebstract Posted March 31, 2008 Author Share Posted March 31, 2008 $result = mysql_query("SELECT * FROM albums ORDER BY id ASC") or DIE(mysql_error()); while($r=mysql_fetch_array($result)) { $id=$r["id"]; $superid=$r["superid"]; $date_created=$r["date_created"]; $date_modified=$r["date_modified"]; $title=$r["title"]; $bg_color=$r["bg_color"]; echo "<li><a href=\"index.php?page=edit&edit=$superid\">edit</a> | <a href=\"index.php?page=album&album=$superid\">$title</a></li>"; $date_created_readable = date('m/d/Y', $date_created); echo "$date_created_readable"; } and when I echo the date_created, it displays a unique timestamp for each result.. Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506042 Share on other sites More sharing options...
PFMaBiSmAd Posted March 31, 2008 Share Posted March 31, 2008 If they were all created on the same date, but at different times, you would get the same output from the code. If you add the time to the format string, the example number in the first post is actually - 01/15/2008 15:17:17 Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506045 Share on other sites More sharing options...
discomatt Posted March 31, 2008 Share Posted March 31, 2008 If we could see some sample timestamps in your DB we could help debug your issue a little faster. Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506047 Share on other sites More sharing options...
aebstract Posted March 31, 2008 Author Share Posted March 31, 2008 It works, the difference in time is actually in seconds. Sorry for the confusion and thanks for the help. Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506052 Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 Yes, it appears most are on the same day. <?php $str = '1200594207 1200435878 1200435906 1200435913 1200435925 1200435930'; foreach (explode("\n", $str) as $stamp) echo date ('m/d/Y h:i:s', $stamp) . '<br>'; ?> Returns 01/17/2008 10:23:27 01/15/2008 02:24:38 01/15/2008 02:25:06 01/15/2008 02:25:13 01/15/2008 02:25:25 01/15/2008 02:25:30 Link to comment https://forums.phpfreaks.com/topic/98898-display-date-readable/#findComment-506055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.