phporcaffeine Posted April 23, 2006 Share Posted April 23, 2006 <?php//$TIMESTAMP IS THE RESULT OF THE SUBTRACTION OF TWO TIMESTAMPS//THE GOAL IS TO GET THE DIFFERENCE BETWEEN TWO TIMESTAMPS AND THEN USE DATE() TO FORMAT IT//INTO SOMETHING PEOPLE THAT CAN'T COUNT SECONDS CAN READ.$timestamp = 1829;echo date(h:i:s, $timestamp);//The result is that date() grabs the seconds and minutes right but for the hour, it will consistantly return the//number ' 7 ', even if the stamp hasn't reached a single hour yet?>Anyone have any ideas?P.S in php.ini I have my timezone = US/Eastern Quote Link to comment Share on other sites More sharing options...
Barand Posted April 23, 2006 Share Posted April 23, 2006 [code]$timestamp = 1829;echo date('h:i:s', $timestamp);[/code]--> 12:30:29The 5 hour difference between our results will be the timezone diff (I'm GMT +0 and you are GMT -5)try[code]$s = $timestamp%60;$i = floor($timestamp / 60);$h = floor ($i / 60);echo "$h:$i:$s"; // --> 0:30:29[/code] Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted April 23, 2006 Author Share Posted April 23, 2006 [!--quoteo(post=367750:date=Apr 23 2006, 03:01 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 23 2006, 03:01 PM) [snapback]367750[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$timestamp = 1829;echo date('h:i:s', $timestamp);[/code]--> 12:30:29The 5 hour difference between our results will be the timezone diff (I'm GMT +0 and you are GMT -5)try[code]$s = $timestamp%60;$i = floor($timestamp / 60);$h = floor ($i / 60);echo "$h:$i:$s"; // --> 0:30:29[/code][/quote]!@# PERFECTO !@#Now, for my own edumaction, could you explain why I wasn't able to do it with date()?I thought of one other thing -lets say the timestamp if formatted and it comes out to be 0:59:59.in a momeny it will read 1:60:xx then 1:61:xx is there an easy way to make it so that at 60 minutes it rolls back to 0 minutes and bumps up the hour ( the same goes for seconds ).Thats why I was trying to use date() for that, because it will ' automagically ' do that. Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted April 23, 2006 Author Share Posted April 23, 2006 Here is the solution to my last question if anyone cares:$s = $savedstamp%60; $i = floor($savedstamp / 60); $h = floor ($i / 60); //This takes the minutes subtracted by the number of hours X 60//In effect, the minute column will never show above 60 minutes but will still be in correct sync with the//seconds and the hour(s)$real_i = $i - $h * 60; Quote Link to comment Share on other sites More sharing options...
Barand Posted April 23, 2006 Share Posted April 23, 2006 or[code]$timestamp = 3599+1;$h = floor ($timestamp / 3600);$timestamp %= 3600;$i = floor($timestamp / 60);$s = $timestamp%60;printf ('%d:%02d:%02d', $h,$i,$s);[/code]As for your other question, I'm not sure why I got 12 hrs and not 0 (GMT) but I was expecting the 5 hour difference just because I've seen the same problem before.EDITI just tried[code]$timestamp = 1829;echo date ('H:i:s', $timestamp); // note 'H' and not 'h'[/code]--> 00:30:29 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.