Created
June 16, 2020 11:21
-
-
Save Stoltze/8187f68499527f50329b7f5d02ecf971 to your computer and use it in GitHub Desktop.
A function that shows how long time is has been something. Ie. "4 minutes ago"
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
function TimeAgo ($oldTime, $newTime) { | |
$timeCalc = strtotime($newTime) - strtotime($oldTime); | |
if ($timeCalc >= (60*60*24*30*12*2)){ | |
$timeCalc = intval($timeCalc/60/60/24/30/12) . " years ago"; | |
}else if ($timeCalc >= (60*60*24*30*12)){ | |
$timeCalc = intval($timeCalc/60/60/24/30/12) . " year ago"; | |
}else if ($timeCalc >= (60*60*24*30*2)){ | |
$timeCalc = intval($timeCalc/60/60/24/30) . " months ago"; | |
}else if ($timeCalc >= (60*60*24*30)){ | |
$timeCalc = intval($timeCalc/60/60/24/30) . " month ago"; | |
}else if ($timeCalc >= (60*60*24*2)){ | |
$timeCalc = intval($timeCalc/60/60/24) . " days ago"; | |
}else if ($timeCalc >= (60*60*24)){ | |
$timeCalc = " Yesterday"; | |
}else if ($timeCalc >= (60*60*2)){ | |
$timeCalc = intval($timeCalc/60/60) . " hours ago"; | |
}else if ($timeCalc >= (60*60)){ | |
$timeCalc = intval($timeCalc/60/60) . " hour ago"; | |
}else if ($timeCalc >= 60*2){ | |
$timeCalc = intval($timeCalc/60) . " minutes ago"; | |
}else if ($timeCalc >= 60){ | |
$timeCalc = intval($timeCalc/60) . " minute ago"; | |
}else if ($timeCalc > 0){ | |
$timeCalc .= " seconds ago"; | |
} | |
return $timeCalc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment