Jump to content
• Sign Up

#### Archived

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

# Changing Time Stamp into hours minutes seconds?

## Recommended Posts

Hey I was wondering how I could change the outputed 15600 seconds into the number ofd hours minutes and seconds? I need this for a count down feature.

Is there a function that can do this? I have looked around but only confused myself

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
[!--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]

#### Share this post

##### Share on other sites
Bah... they didn't ask about days... and I'm results oriented... EFFICIENCY IS KEY! ;-)

#### Share this post

##### Share on other sites
[!--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 ;-)

#### Share this post

##### Share on other sites
I read the post and thinking issint it better to insert the data in this format \$count_down_time=date("hms");
and then use a for loop to count down.

#### Share this post

##### Share on other sites
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

×

• Chat

## 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.