MySQL的str_to_date问题 [英] MySQL str_to_date problem
问题描述
这是怎么了? str_to_date('26/04/2011 00:00:00', '%d/%m/%Y')
它给出了Error Code: 1292 Truncated incorrect date value: '26/04/2011 00:00:00'
What's wrong with this? str_to_date('26/04/2011 00:00:00', '%d/%m/%Y')
It gives Error Code: 1292 Truncated incorrect date value: '26/04/2011 00:00:00'
更新:问题是00:00:00
,如果我将其删除,它会起作用.如何编辑'%d/%m/%Y'
以接受时间? '%d/%m/%Y %h:%m:%s'
不起作用.
Update: The problem is the 00:00:00
, if I remove it it works. How can edit the '%d/%m/%Y'
to accept the time? '%d/%m/%Y %h:%m:%s'
doesn't work.
推荐答案
由于您已经在value参数中指定了时间,因此您还应该在date格式参数中指定时间分量.
Since you've specified the time in the value parameter, you should also specify the time components in the date format parameter.
str_to_date('26/04/2011 00:00:00', '%d/%m/%Y %h:%i:%s')
要么,要么从您的日期值中删除时间部分:
either that, or drop the time component from your date value:
str_to_date('26/04/2011', '%d/%m/%Y')
两者都应该起作用,但是您需要在两个参数之间保持一致.
either should work, but you need to be consistent between the two parameters.
或者,您可以指定格式,使其在时间部分具有固定值:
Alternatively, you could specify the format so that it has fixed values in the time component:
str_to_date('26/04/2011 00:00:00', '%d/%m/%Y 00:00:00')
这将起作用,但前提是时间分量始终为00:00:00
.
this will work, but only if the time component is always 00:00:00
.
这篇关于MySQL的str_to_date问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!