开发者

Merge date from one datetime and time from another datetime

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜