Jump to content

Recommended Posts

No function I know of... you'll just have to do a little math.
[code]$hours = floor($total_secs / 3600);
$min = floor(($total_secs % 3600) / 60);
$sec = floor(($total_secs % 3600) % 60);[/code]

Heh... I just came up with that... I might have to use that somewhere.
[!--quoteo(post=380974:date=Jun 7 2006, 08:41 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 7 2006, 08:41 AM) [snapback]380974[/snapback][/div][div class=\'quotemain\'][!--quotec--]
No function I know of... you'll just have to do a little math.
[code]$hours = floor($total_secs / 3600);
$min = floor(($total_secs % 3600) / 60);
$sec = floor(($total_secs % 3600) % 60);[/code]

Heh... I just came up with that... I might have to use that somewhere.
[/quote]

lol... very similar to what i wrote up earlier this morning, too, ober... i was a little more verbose to aid in understanding, though:
[code]
function getTimeDiff($ts1, $ts2) {
  $diff = abs($ts1 - $ts2);

  $sec = 1;
  $min = $sec * 60;
  $hour = $min * 60;
  $day = $hour * 24;

  $dayDiff = floor($diff / $day);
  $diff = $diff % $day;
  $hourDiff = floor($diff / $hour);
  $diff = $diff % $hour;
  $minDiff = floor($diff / $min);
  $secDiff = $diff % $min;
  
  return "$dayDiff days $hourDiff hours $minDiff mins $secDiff seconds";
}

echo getTimeDiff(time(), mktime(0,0,0,12,2,2005));
[/code]
[!--quoteo(post=380977:date=Jun 7 2006, 08:47 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 7 2006, 08:47 AM) [snapback]380977[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Bah... they didn't ask about days... and I'm results oriented... EFFICIENCY IS KEY! ;-)
[/quote]

lol... i know, but in the thread i answered with that function, they DID ask about days ;-)
Here's a function I just came up with that uses the standard date() and strtotime() functions:
[code]<?php
function get_hms($secs) {
     if ($secs > 86400) return (false);
     $mid = strtotime(date('Y-m-d 00:00:00',strtotime('now')));
     list($hns['hour'],$hms['min'],$hms['sec']) = explode(':', date('G:i:s',$mid + $secs));
     return($hms);
}?>[/code]

Returns an array containing the number of Hours, Minutes, Second or FALSE if the input number is more than a day (86,400 seconds).

Ken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.