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
Share on other sites

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.

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.