我想从时间戳字段中获取日期部分。 我用这个SQL查询:为什么CAST()函数返回错误的日期?
select timestamp, CAST(timestamp as date) as date from messages
我得到了以下结果:
--------------------------------------------
| timestamp | date |
--------------------------------------------
| 2016-05-15 10:22:54 | 2016-05-16 |
--------------------------------------------
如上所示,日期字段产生返回错误的日期2016-05-16
而原始日期是2016-05-15
。
我们该如何解决这个问题?
伟大的答案。感谢它像魅力一样工作。 但DATE_FORMAT()函数也会产生错误的格式。这是为什么? – user2899728
Date()提取有效日期时间的日期部分,,, Date_format更改日期的方面......你使用什么格式..? – scaisEdge
我使用了'%d%M,%Y' – user2899728