Jump to content

Adjusting Timestamp


Pizzanova

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/293811-adjusting-timestamp/#findComment-1502420
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.