EchoFool Posted April 26, 2010 Share Posted April 26, 2010 Is there any premade functions that change input of an integer in to a string of values like: Years : Months : Weeks : Days : Hours : Minutes Say the input was 120 minutes.... then the output would come out as Hours 2 But then if you had 1440 minutes it'll return 1 Day Or will i have to make the function? Link to comment https://forums.phpfreaks.com/topic/199805-time-output-from-function/ Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 You'd most likely have to make the function. You could cheat with the strftime function, but it wouldn't work well. The function would be pretty simple: function time_f($minutes) { $output = '' $min = $minutes % 60; //Get the minutes 0-59 if($min) $output .= $min . ' minutes'; $hours = intval($minutes/60); if($hours % 24) $output .= $hours % 24 . ' hours'; $days = intval($hours/24); if($days % 356) $output .= $days % 356 . ' days'; $years = intval($days/356); if($years) $output .= $years . ' years'; return $output; } Sometime like that is a rough start Link to comment https://forums.phpfreaks.com/topic/199805-time-output-from-function/#findComment-1048744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.