合并一个日期时间的日期和另一个日期时间的时间 [英] Merge date from one datetime and time from another datetime

查看:89
本文介绍了合并一个日期时间的日期和另一个日期时间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在维护一个数据库,其中事件的日期和时间是分开的,但是都保存为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'))

这篇关于合并一个日期时间的日期和另一个日期时间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆