rofl90 Posted June 30, 2008 Share Posted June 30, 2008 $originalM should work out to be around 25000 after preliminary calculations, i'm inputting a timestamp about 3 days old. This code outputs 876970800 days, 0 hours ago It should be something like 2 days 17 hours or what not. Here is the function: public static function since($original) { if(!strtotime($original)) { $originalA = (int)$original; } else { $originalA = strtotime($original); } $originalM = (int)(time() - $originalA); if($originalM < ((int)(60))) { return $originalM . " seconds ago"; } elseif($originalM < ((int)(60 * 60))) { return floor($originalM) . " minutes, " . ($originalM - floor($originalM)) . " seconds ago"; } elseif($originalM < ((int)(60 * 60 * 24))) { $originalM = $originalM * 60; return floor($originalM) . " hours, " . ($originalM - floor($originalM)) . " minutes ago"; } elseif($originalM < ((int)(60 * 60 * 24 * 30))) { $originalM = $originalM * 3600; return floor($originalM) . " days, " . ($originalM - floor($originalM)) . " hours ago"; } elseif($originalM < ((int)(60 * 60 * 24 * 365))) { $originalM = $originalM * 86400; return floor($originalM) . " months, " . ($originalM - floor($originalM)) . " days ago"; } else { $originalM = $originalM * 31536000; return floor($originalM) . " years, " . ($originalM - floor($originalM)) . " days ago"; } } Link to comment https://forums.phpfreaks.com/topic/112603-function-isnt-working/ Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 Check out this: http://us2.php.net/manual/en/function.time.php#83560 Link to comment https://forums.phpfreaks.com/topic/112603-function-isnt-working/#findComment-578294 Share on other sites More sharing options...
rofl90 Posted June 30, 2008 Author Share Posted June 30, 2008 How would I format this to how I wanted Link to comment https://forums.phpfreaks.com/topic/112603-function-isnt-working/#findComment-578443 Share on other sites More sharing options...
LooieENG Posted June 30, 2008 Share Posted June 30, 2008 <?php //Outputs YYYY-MM-DD HH:MM:SS (remove letters as necessary) date('Y-M-D H:i:s', $timestampVar); ?> Edit: date(), not time() Link to comment https://forums.phpfreaks.com/topic/112603-function-isnt-working/#findComment-578455 Share on other sites More sharing options...
rhodesa Posted June 30, 2008 Share Posted June 30, 2008 <?php function since ( $original ){ $original = strtotime($original) ? strtotime($original) : $original; $diff = time() - $original; $out = ""; $a = array('year'=>31556926, 'month'=>2629744, 'week'=>604800, 'day'=>86400, 'hour'=>3600, 'minute'=>60, 'second'=>1); foreach($a as $k=>$v){ $n = floor($diff / $v); if($n) $out .= "$n $k".($n===1?' ':'s '); $diff = $diff % $v; } return trim($out); } print since(1213934400); ?> Link to comment https://forums.phpfreaks.com/topic/112603-function-isnt-working/#findComment-578460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.