开发者

Merge date from one datetime and time from another datetime

开发者 https://www.devze.com 2022-12-22 11:35 出处:网络
I\'m maintaining a database where the date and the time of events are s开发者_Go百科eperated, both are saved as datetime though.

I'm maintaining a database where the date and the time of events are s开发者_Go百科eperated, both are saved as datetime though.

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


You can use the DATE_FORMAT function in your selects.

For the date:

'%Y-%m-%d'

For time:

'%H:%i:%s'

So something like:

UPDATE `table`
SET `datetimecol` = CONCAT_WS(' ', DATE_FORMAT(`datecol`, '%Y-%m-%d'), DATE_FORMAT(`timecol`, '%H:%i:%s'))
0

精彩评论

暂无评论...
验证码 换一张
取 消