Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting future D:H:M:S from server time

Status
Not open for further replies.

wudz

Programmer
Mar 28, 2001
135
GB
Hi,
wonder if anyone can help, having great difficulty extracting 'Time left'.
I have extracted the required variables from the db, now how do I get the Days, Hours, Minuites and Seconds difference from the present server time below..the timecorrection (-2)is due to using a server time difference from my site, also have I done this correction correctly just reducing the hr by 2hrs( will the days,months etc be OK).


// corrected Server time

$TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));


//db extracted End time

$ends_date = strval($row["ends"]);

$ends_y = substr ($ends_date, 0, 4);

$ends_m = substr ($ends_date, 4, 2);

$ends_d = substr ($ends_date, 6, 2);

$ends_h = substr ($ends_date, 8, 2);

$ends_min = substr ($ends_date, 10, 2);

$ends_sec = substr ($ends_date, 12, 2);

All help appreciated.
Cheers

John
Flash Graphics are my game.......
 
think you've made this too complex. try this instead:

Code:
$dbtime = strtotime($row['ends']);
$timenow = strtotime("-2 hours");
$timediff = $timenow - $dbtime;
echo "time difference is $timediff seconds";

this gives you the number of seconds. not too hard to convert this to days, hrs and minutes etc.

hth
justin
 
i found a small script i'd written to convert seconds to other time units. it might be useful
Code:
function ($seconds) {
$seconds = (float) $seconds;
$secs = round((($seconds/60)-floor($seconds/60)) * 60,1);
$mins = floor((($seconds/3600)-floor($seconds/(3600))) *60) ;
$hrs = floor((($seconds/(3600*24))-floor($seconds/(3600*24))) *24) ;
$days = floor($seconds / (3600*24));
$days = ($days<0) ? 0 : $days;

return  "days: $days, hours: $hrs, mins: $mins, secs: $secs";
}
 
Thanks two both of you, looks like I was trying to crack a nut with a sledge hammer...

The above is great!

Cheers

John
 
both of me? i've always suspected schizophrenia, now others are noticing!
 
GREAT reply jpadie,,,love it..

Sorry form the both of us!

Cheers

John John
 
Man thats like hard work, just make mysql select what you need.

select convert_tz(now(),'+00:00','-02:00')


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
how does that give you the difference between two times? i can see how date_diff might work (but the return format isn't always what one would want) but not convert_tz.

the meat of the function supplied to the user here is in reality only one line of php code. it's the formatting from seconds that takes a few code lines. so not too much like hard work!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top