MySQL: How add an Hour to a DateTime Column Value CodeUnit 29 AUG 2011

If you make use of a datetime column in your MySQL database to store timestamp data, here is a simple way of adding a couple of hours to your already stored value. You know, if the client suddenly decided to change time zone or something like that! ;)

UPDATE `table` SET `datetime-column` = DATE_ADD(`datetime-column`, INTERVAL 2 HOUR) WHERE `id` = 1

You can of course also minus hours by altering the above to add a negative interval:

UPDATE `table` SET `datetime-column` = DATE_ADD(`datetime-column`, INTERVAL -2 HOUR) WHERE `id` = 1

Simple and effective.

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.