Mysql update time column only changes the date to the specified date without changing the time

Scenes

After Mysql splits tables, data is copied between tables with the same structure and different names, and the Update statement only updates the date plus or minus but does not change the time:

After Mysql is divided into tables, data is copied between tables with the same structure and different names, and the Update statement only updates the date plus or minus but does not change the time_Domineering Rogue Temperament Blog-CSDN Blog

The above method is used to add the specified number of days to the date column.

UPDATE bus_vehicle_position_record20230801
SET record_date = DATE_ADD(record_date, INTERVAL 1 DAY)

If the time difference is too long, you don’t want to increase or decrease the number of days. You just want to change the date of a certain time column to the specified date.

But the time period remains unchanged, you can use the following method

Note:

Blog:
Domineering Rogue Temperament_C#, Architecture Road, SpringBoot-CSDN Blog

accomplish

The executed sql is

UPDATE bus_vehicle_position_record20230810 SET record_date = ADDTIME(DATE('2023-08-10') + INTERVAL 0 HOUR,TIME(record_date))

Among them, bus_vehicle_position_record20230810 is the table name, and record_date is the time column to be changed.

Obtain the date information of the specified date character through the DATE function, obtain the time information of the previous data through the TIME function, and then add them together through the ADDTIME function.

Guess you like

Origin blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/132742518