Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update datetime by +15 hours with MySQL

Tags:

datetime

mysql

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?

like image 345
user3278770 Avatar asked Feb 25 '16 11:02

user3278770


2 Answers

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

like image 179
sqrepants Avatar answered Nov 19 '22 12:11

sqrepants


update table_name set column_name =DATE_ADD(column_name, INTERVAL 15 HOUR)
like image 27
Ankit Agrawal Avatar answered Nov 19 '22 12:11

Ankit Agrawal