Jump to content

Time output from function


EchoFool

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.