president vankk
Web Developer & AuraOT Owner
- Joined
- Jul 10, 2009
- Messages
- 5,719
- Solutions
- 9
- Reaction score
- 339
Hi dear friends,
What is the problem with this function below? It is returning a number too high.
For example: 225 days, 16 hours and 16 minutes
Thanks.
What is the problem with this function below? It is returning a number too high.
Code:
function getTimeString($seconds)
{
$text = "";
$days = floor(($seconds / 3600) / 24);
$hours = floor(($seconds / 3600) % 24);
$minutes = floor(($seconds / 3600) % 60);
if ($days != 0) {
if ($days > 1) {
$text .= $days . " days";
} else {
$text .= "1 day";
}
}
if ($hours != 0) {
if ($days != 0) {
$text .= ", ";
}
if ($hours > 1) {
$text .= $hours . " hours";
} else {
$text .= "1 hour";
}
}
if ($minutes != 0) {
if ($days != 0 || $hours != 0) {
$text .= " and ";
}
if ($minutes > 1) {
$text .= $minutes ." minutes";
} else {
$text .= "1 minute";
}
}
return $text;
}
For example: 225 days, 16 hours and 16 minutes
Thanks.