Page 1 of 1
RESULT IN SECONDS - CONVERTING TO DAYS H M S
Posted: Tue Oct 25, 2005 12:14 pm
by poeta_eletrico
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi,
I know that s not a huge problem tat all and I really can play with but I was imagining another way to convert a query result given in SECONDS only to a common timestamp like: h: m: s ...
In Action:
I am retrieving data from mysql (the records comes in seconds) - I sum all the results returned, distinctly to every USER in seconds. But, sometimes I have more than one person and I would like to have the total amount, given in TIMESTAMP...any good ideas around?
I have this piece of code working:
Code: Select all
$num=($t_geral/86400);
$days=intval($num);
$num2=($num - $days)*24;
$num3=($num2 - $days)*60;
$mins = intval($num3);
$num4=($num3-$mins)*60;
...any idea to have it in a different way?
Poeta_Eletrico
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Tue Oct 25, 2005 1:36 pm
by hawleyjr
Posted: Tue Oct 25, 2005 2:04 pm
by poeta_eletrico
Hi,
I think that s not possible cos the time I have is in SECONDS not in TIMESTAMP to convert to ... I tried SEC_TO_TIME before but with no success.
Thanks.
Poeta_Eletrico
Posted: Tue Oct 25, 2005 2:08 pm
by hawleyjr
Are you asking for a function to convert seconds into the number of hours, minutes & seconds?
Posted: Tue Oct 25, 2005 2:26 pm
by foobar
Use PHP's
mktime() or
date().
Posted: Tue Oct 25, 2005 3:06 pm
by feyd
Posted: Tue Oct 25, 2005 10:08 pm
by poeta_eletrico
Hi,
But the format inserted, was not parsed the way that turns it possible...imagine I giving u something like
Thank u for ur answer.
Poeta_Eletrico
Posted: Tue Oct 25, 2005 10:09 pm
by poeta_eletrico
hawleyjr wrote:Are you asking for a function to convert seconds into the number of hours, minutes & seconds?
Hi,
It s not properly a FUNCTION but the best way and reasonable one...
Poeta_Eletrico
Posted: Wed Oct 26, 2005 5:02 am
by n00b Saibot
have you seen the link feyd posted

Posted: Wed Oct 26, 2005 7:12 am
by foobar
poeta_eletrico wrote:
Hi,
But the format inserted, was not parsed the way that turns it possible...imagine I giving u something like
Thank u for ur answer.
Poeta_Eletrico
I'm not really sure what you're trying to say here, but it seems as though you're having problems with the functions' syntax. Check the
date() function for the format syntax.
Posted: Wed Oct 26, 2005 7:15 am
by Jenk
Ok, he is not looking for a DATE, he is looking to convert, for example, 23452340958024958 seconds into 15years, 5months, 3 weeks and 22days (or what ever it actually works out to be)
So the date() function is of no use.
Hence his mentioning of no timestamp, so stop suggesting he use the date() function!
Posted: Fri Nov 04, 2005 4:30 am
by poeta_eletrico
Jenk wrote:Ok, he is not looking for a DATE, he is looking to convert, for example, 23452340958024958 seconds into 15years, 5months, 3 weeks and 22days (or what ever it actually works out to be)
So the date() function is of no use.
Hence his mentioning of no timestamp, so stop suggesting he use the date() function!
Hi,
Sorry for my delay respond some posts here but at this moment I am on a vocation...although, Jenk is right...I know the time generated by my server is only in SECONDS...thats the way...
Thank all of you anyway...
Poeta_Eletrico
Posted: Fri Nov 04, 2005 5:36 am
by TJ
This is concise:
Code: Select all
$t = 648478; // elapsed seconds
$s=($d=$t-604800*($weeks = floor($t/604800)))-($h=$d-86400*($days = floor($d/86400)))-($m=$h-3600*($hours = floor($h/3600)))-($seconds=$m-60*($minutes = floor($m/60)));
echo "elapsed $t seconds = $weeks weeks, $days days, $hours hours, $minutes minutes, $seconds seconds";
Posted: Sun Nov 06, 2005 4:44 am
by poeta_eletrico
TJ wrote:This is concise:
Code: Select all
$t = 648478; // elapsed seconds
$s=($d=$t-604800*($weeks = floor($t/604800)))-($h=$d-86400*($days = floor($d/86400)))-($m=$h-3600*($hours = floor($h/3600)))-($seconds=$m-60*($minutes = floor($m/60)));
echo "elapsed $t seconds = $weeks weeks, $days days, $hours hours, $minutes minutes, $seconds seconds";
TJ,
Perfect !

Better than expected !
Thank you for your time consumed here writing this piece of code.
Poeta_Eletrico