Alex Rivera | Logout

Update only Time in a mysql DateTime field

Asked 2009-08-25T07:23:03.377
44

How can I update only the time in an already existing DateTime field in MySQL? I want the date to stay the same.

Edit
Report

3 Answers

81

Try this:

UPDATE yourtable 
SET yourcolumn = concat(date(yourcolumn), ' 21:00:00')
WHERE Id = yourid;
answered 2011-02-11T15:38:54.167
5
UPDATE myTable
SET myDateTime = ADDTIME(DATE(myDateTime), @myTimeSpan)
WHERE id = @id;

Documented on MySQl date functions MySQL docs

answered 2009-09-08T23:41:52.570
0

Well, exactly what you are asking for is not possible. The date and time components can't be updated separately, so you have to calculate the new DateTime value from the existing one so that you can replace the whole value.

answered 2009-08-25T07:39:36.497

Your Answer