Reputation: 7708
I'm wondering if there's an easy way to set a datetime field in MySQL relative to UTC_TIMESTAMP(). E.g., if I want to set it to 1 hour in the past, is there some equivalent of
UPDATE table_name set datetime_col=(UTC_TIMESTAMP()-3600) where ...
(If I try the above it sets the datetime field to 00-00-0000 00:00:00)
Upvotes: 2
Views: 1333
Reputation: 18578
try this:
UPDATE table_name set datetime_col=DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR)
Upvotes: 4
Reputation: 51200
DATE_ADD(UTC_TIMESTAMP() - INTERVAL 1 HOUR)
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
Upvotes: 1