Stefan Kolev Stefan Kolev - 3 years ago 60
MySQL Question

MySQL - update the row's date and save the time

I want to update a row which has timestamp datatype named date_start. Here's an example:

date_start = 2017-04-26 12:34:11

I want to update it, but to save the time, so it'll look like this:

date_start = 2017-05-28 12:34:11

Any ideas? So far I tried extract method and concat method.

Best Regards..

Answer Source

If you just want to update the date component of the timestamp while retaining the time component then you can build the updated timestamp using string concatenation with TIME():

UPDATE yourTable
SET date_start = CONCAT('2017-05-28 ', TIME(date_start))
WHERE <some condition>


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download