Created
January 18, 2011 21:28
-
-
Save brianherbert/785189 to your computer and use it in GitHub Desktop.
This is a function that returns a string stating the amount of time has passed from one timestamp to another.
This file contains 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 daysago($now,$then){ | |
$daycount = floor(($now-$then)/86400); //86400 seconds in a day | |
$hourcount = floor(($now-$then)/3600); //3600 seconds in an hour | |
$minutecount = floor(($now-$then)/60); //60 seconds in a minute | |
if($daycount == 0) { | |
$str = 'Created '; | |
if($hourcount != 0) { | |
$str .= $hourcount.' '; | |
if($hourcount == 1) { | |
$str .= 'hour'; | |
}else{ | |
$str .= 'hours'; | |
} | |
$str .= ' and '; | |
} | |
$str .= $minutecount.' '; | |
if($minutecount == 1) { | |
$str .= 'minute'; | |
}else{ | |
$str .= 'minutes'; | |
} | |
$str .= ' ago.'; | |
return $str; | |
} | |
if($daycount == 1) { | |
return 'Created '.$daycount.' day ago.'; | |
} | |
return 'Created '.$daycount.' days ago.'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment