合并一个日期时间的日期和另一个日期时间的时间
问题描述:
我正在维护一个数据库,其中事件的日期和时间是分开的,但是都保存为datetime.
I'm maintaining a database where the date and the time of events are seperated, both are saved as datetime though.
那么我该如何从日期"列中提取日期,并从时间"列中提取时间,并将其插入到"datetime"列中
So How do I pull the date from the "date" Column, and the time from the "time" column and insert it into the "datetime"-column
答
您可以使用日期:
'%Y-%m-%d'
时间:
'%H:%i:%s'
类似这样:
UPDATE `table`
SET `datetimecol` = CONCAT_WS(' ', DATE_FORMAT(`datecol`, '%Y-%m-%d'), DATE_FORMAT(`timecol`, '%H:%i:%s'))