Nick
Nick

Reputation: 4462

Adding one hour to UTC_TIMESTAMP for submission to MySQL

I am using the following code to submit the UTC_TIMESTAMP to a MySQL database:

$logq = "INSERT INTO logs (Name, Page, Date) VALUES ('$user', '$page', UTC_TIMESTAMP())";

I am in the UK and the time is currently one hour ahead of the UTC_TIMESTAMP, so I would like to add one hour to the values entered, but I'm not sure how to do this. I tried a couple of suggestions found on Stack Overflow, but both don't work. Could someone let me know how to do this correctly? Also, I am not sure how to handle daylight saving time. Is there a way of accounting for this automatically?

Thanks,

Nick

Upvotes: 4

Views: 4772

Answers (5)

raftaar1191
raftaar1191

Reputation: 373

This also works SELECT DATE_ADD( UTC_TIMESTAMP(), INTERVAL 1 DAY)

Upvotes: 0

thevikas
thevikas

Reputation: 1639

The mysql datatype TIMESTAMP is always UTC no matter where are. You have a function FROM_UNIXTIME which converts timestamp internally into standard YYYY-MM-DD HH:SS format. When using the function FROM_UNIXTIME it will convert that UTC to your local timezone automatically. So you won't need to adjust times and accounting will always be good no matter your daylight status.

Upvotes: 2

Er. Anurag Jain
Er. Anurag Jain

Reputation: 1793

Please use ADDDATE function of mysql, using this you can add Hour/Month/Day in any date.

 ADDDATE( UTC_TIMESTAMP(), INTERVAL 1 HOUR)

Please look the url given below belongs to mysql date time function

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

thanks

Upvotes: 1

Valour
Valour

Reputation: 810

After you created a connection to the database in PHP, query this code before any query:

mysql_query("SET time_zone = '+3:00'");

I did not tried it but it should do the trick.

Some links about this:

Upvotes: 0

lafor
lafor

Reputation: 12776

DATE_ADD(UTC_TIMESTAMP(), INTERVAL 1 HOUR)

Upvotes: 13

Related Questions