Sign in to follow this  
Third

[web] Time from a timestamp in PHP

Recommended Posts

Third    121
I have a UNIX timestamp that I need to convert into hours:minutes:seconds. I tried using gmstrftime("%H:%M:%S", $timestamp) but that does not return the total hours. An example is say the timstamp equals 54 hours, 36 minutes, 54 seconds in GMT, what function in PHP would return that correctly? Thanks!

Share this post


Link to post
Share on other sites
Mathachew    352
Er, timestamp's do not equal 54 hours, 36 minutes, 54 seconds, an interval, however, does.

Are you wanting to get the interval from one point in time to another? Or are you wanting to get the hour, minutes and seconds from a timestamp? I ask this because it seems you're wanting an interval but are pulling it based on a single timestamp with no other point of reference, which an interval needs (unless you're counting from the beginning of time).

Share this post


Link to post
Share on other sites
Third    121
Quote:
Original post by Mathachew
Er, timestamp's do not equal 54 hours, 36 minutes, 54 seconds, an interval, however, does.

Are you wanting to get the interval from one point in time to another? Or are you wanting to get the hour, minutes and seconds from a timestamp? I ask this because it seems you're wanting an interval but are pulling it based on a single timestamp with no other point of reference, which an interval needs (unless you're counting from the beginning of time).


Ah yes, you're right. I'll try to explain more what I need then to see if anyone has a solution. I'm calculating the interval between two times and adding them to a timestamp(I first convert the two times into timestamps). At the end I then have the timestamp with the total time of all the intervals added together, correct? If that's true then I need that time returned in the format of total hours, minutes, and seconds. What would be the best way to go about doing this?

I appreciate the help so far.

Share this post


Link to post
Share on other sites
Mathachew    352
Quote:
Original post by Third
Ah yes, you're right. I'll try to explain more what I need then to see if anyone has a solution. I'm calculating the interval between two times and adding them to a timestamp(I first convert the two times into timestamps). At the end I then have the timestamp with the total time of all the intervals added together, correct? If that's true then I need that time returned in the format of total hours, minutes, and seconds. What would be the best way to go about doing this?

I appreciate the help so far.


http://aidan.dotgeek.org/repos/?file=Duration.php

This script returns the duration based on the number of seconds passed to it. Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this