mysql只修改年月日,时分秒不变

方法一:使用DATE_ADD()函数

  • 时间前移:2020-01-07 10:06:36 改为 2020-01-05 10:06:36

   

UPDATE clear_detail SET modified_date = DATE_ADD(modified_date,INTERVAL -2 DAY) WHERE id =9264531 ;

  

  • 时间后移:2020-01-07 10:06:36 改为 2020-01-09 10:06:36

  

UPDATE clear_detail SET modified_date = DATE_ADD(modified_date,INTERVAL  2 DAY) WHERE id =9264530 ;

  

 

方法二:用ADDTIME()函数

  

UPDATE clear_detail SET modified_date=ADDTIME(DATE("2020-01-05") + INTERVAL 0 HOUR,TIME(modified_date)) WHERE id =9264532;

  

  如要改为当前日期:

  UPDATE clear_detail SET modified_date=ADDTIME(CURRENT_DATE() + INTERVAL 0 HOUR,TIME(modified_date)) WHERE id =9264532;

  

posted @ 2020-01-07 10:44  pandaly  阅读(2742)  评论(0编辑  收藏  举报