Unlimited Usenet
day retention, 99% Completion, Unlimited Access, Free Trial!

RE: [PHP] Need to convert seconds to DD:HH:MM:SS

This is a discussion on RE: [PHP] Need to convert seconds to DD:HH:MM:SS within the PHP General forums, part of the PHP Programming Forums category; >can't seem to figure > out how to get the number of days integrated in here for $hh ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-19-2003
Jennifer Goodie
 
Posts: n/a
Default RE: [PHP] Need to convert seconds to DD:HH:MM:SS

>can't seem to figure
> out how to get the number of days integrated in here for $hh that
> are > 24.
> to days:hours:minutes:seconds... This function works for what it
> does, can
> someone embelish it to handle days too?
>
> function convertToHHMMSS($seconds)
> {
> $hoursPerDay = 24;
> $SecondsPerHour = 3600;
> $SecondsPerMinute = 60;
> $MinutesPerHour = 60;
>
> $hh = intval($seconds / $SecondsPerHour);
> $mm = intval($seconds / $SecondsPerMinute) % $MinutesPerHour;
> $ss = $seconds % $SecondsPerMinute;
>
> return $hh."h:".$mm."m:".$ss."s";
> }


Not quite what you're looking for, but I'm sure you can figure out how to
customize it

function sec2time($sec){
$returnstring = " ";
$days = intval($sec/86400);
$hours = intval ( ($sec/3600) - ($days*24));
$minutes = intval( ($sec - (($days*86400)+ ($hours*3600)))/60);
$seconds = $sec - ( ($days*86400)+($hours*3600)+($minutes * 60));

$returnstring .= ($days)?(($days == 1)? "1 day":"$days days"):"";
$returnstring .= ($days && $hours && !$minutes && !$seconds)?" and
":" ";
$returnstring .= ($hours)?( ($hours == 1)?"1 hour":"$hours
hours"):"";
$returnstring .= (($days || $hours) && ($minutes && !$seconds))?"
and ":" ";
$returnstring .= ($minutes)?( ($minutes == 1)?"1 minute":"$minutes
minutes"):"";
$returnstring .= (($days || $hours || $minutes) && $seconds)?" and
":" ";
$returnstring .= ($seconds)?( ($seconds == 1)?"1 second":"$seconds
seconds"):"";
return ($returnstring);
}
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:28 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0