Pizzanova Posted January 10, 2015 Share Posted January 10, 2015 I've been having problems displaying the correct time when extracting timestamp for a graph. Wasted a lot of time trying to adjust for timezone and then finding that it didn't help. Now trying to add 2 hours to the timestamp and not sure how. Here is the line that needs to be changed I believe. $Date=substr(mysql_result($result,$i,"Date"),11,5); Can someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/ Share on other sites More sharing options...
QuickOldCar Posted January 10, 2015 Share Posted January 10, 2015 Not sure what you have going on there, but you can modify the date using strtotime And sure, changing the timezone wouldn't help for the past inserted ones, only make more of a mess. Quote Link to comment https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/#findComment-1502416 Share on other sites More sharing options...
Pizzanova Posted January 10, 2015 Author Share Posted January 10, 2015 Thanks. I see now I didn't give you enough code to explain. Also, I Really am a newb. But I will look this up and see if I can figure out how to change my code to make it work. The "Date" field of the db is simply the timestamp. I want to add 2 hours to this. Quote Link to comment https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/#findComment-1502418 Share on other sites More sharing options...
Barand Posted January 10, 2015 Share Posted January 10, 2015 This will take your date field, add 2 hours and format as time $dt = new DateTime(mysql_result($result,$i,"Date")); $adjustedTime = $dt->add(new DateInterval('PT2H'))->format('H:i'); Don't use mysql_ functions, you will only have to rewrite them all soon when they disappear from PHP and you certainly should not be using mysql_result(). You should be using xxx_fetch_row() or xxx_fetch_assoc() as they are far more efficient Quote Link to comment https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/#findComment-1502420 Share on other sites More sharing options...
CroNiX Posted January 10, 2015 Share Posted January 10, 2015 You can also add and subtract time directly in the query itself and not use php at all. SELECT DATE_ADD(your_date_column, INTERVAL 2 HOUR) AS incremented_date Quote Link to comment https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/#findComment-1502423 Share on other sites More sharing options...
Barand Posted January 10, 2015 Share Posted January 10, 2015 While your at it you may as well format it too in the SQL SELECT DATE_FORMAT(date + INTERVAL 2 HOUR, '%H:%i') as time, ... Quote Link to comment https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/#findComment-1502425 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.