8

I have a table containing a datetime column.

I need to add 15 hours to all these values.

e.g.

As Is: 2007-08-22 08:55:10  
To Be: 2007-08-22 23:55:10

As Is: 2009-08-22 14:55:10  
To Be: 2009-08-23 05:55:10

Is there a MySQL UPDATE query that can do this?

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
user3278770
  • 149
  • 1
  • 1
  • 7
  • Possible duplicate of [Add 2 hours to current time in MySQL?](http://stackoverflow.com/questions/589652/add-2-hours-to-current-time-in-mysql) – rghome Feb 25 '16 at 11:53
  • There are already questions on how to add a time interval in mysql – rghome Feb 25 '16 at 11:54

3 Answers3

28

Given that test is the table, date_col is the column with the date to be updated and id is the primary key of the test table:

update test set date_col = ADDTIME(date_col, '15:0:0') where id=1;

tested with mysql version 5.5.4

sqrepants
  • 996
  • 2
  • 10
  • 22
8
update table_name set column_name =DATE_ADD(column_name, INTERVAL 15 HOUR)
Ankit Agrawal
  • 2,426
  • 1
  • 13
  • 27
0

update table_name set column_name = ADDTIME(column_name, '15:0:0');

bhrached
  • 127
  • 1
  • 9