Created
May 30, 2011 21:30
-
-
Save jamsesso/999504 to your computer and use it in GitHub Desktop.
Supply a time stamp, get a time ago statement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function str_time($stamp) | |
{ | |
$difference = time() - $stamp; | |
$intervals = array( | |
'minute' => 60, | |
'hour' => 3600, | |
'day' => 86400, | |
'month' => 2628000, | |
'year' => 31536000 | |
); | |
$time_ago = 'Unknown time ago.'; | |
if($difference >= $intervals['year']) | |
$time_ago = ((string) round($difference / $intervals['year'])).' years ago.'; | |
elseif($difference >= $intervals['month']) | |
$time_ago = ((string) round($difference / $intervals['month'])).' months ago.'; | |
elseif($difference >= $intervals['day']) | |
$time_ago = ((string) round($difference / $intervals['day'])).' days ago.'; | |
elseif($difference >= $intervals['hour']) | |
$time_ago = ((string) round($difference / $intervals['hour'])).' hours ago.'; | |
elseif($difference >= $intervals['minute']) | |
$time_ago = ((string) round($difference / $intervals['minute'])).' minutes ago.'; | |
elseif($difference < $intervals['minute']) | |
$time_ago = ((string) $difference).' seconds ago.'; | |
return $time_ago; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment