Created
August 22, 2012 13:12
-
-
Save peponi/3425414 to your computer and use it in GitHub Desktop.
Convert UNIX timestamp to days hours minute seconds
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 GetTimeDiff($timestamp) | |
{ | |
$how_log_ago = ''; | |
$seconds = time() - $timestamp; | |
$minutes = (int)($seconds / 60); | |
$hours = (int)($minutes / 60); | |
$days = (int)($hours / 24); | |
if ($days >= 1) { | |
$how_log_ago = $days . ' day' . ($days != 1 ? 's' : ''); | |
} else if ($hours >= 1) { | |
$how_log_ago = $hours . ' hour' . ($hours != 1 ? 's' : ''); | |
} else if ($minutes >= 1) { | |
$how_log_ago = $minutes . ' minute' . ($minutes != 1 ? 's' : ''); | |
} else { | |
$how_log_ago = $seconds . ' second' . ($seconds != 1 ? 's' : ''); | |
} | |
return $how_log_ago; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment