运算符与日期之间的mysql

select '2011-02-29' BETWEEN '2011-02-01' AND '2011-03-03'‎

这是回归1.我认为之间不考虑闰年.我想要你的观点吗?

[编辑]
SELECT DATE(‘2010-04-31’)返回NULL;
但是选择str_to_date(‘2010-04-31′,’%Y-%m-%d’)是重新调整日期.

为什么?

谢谢
VENU

解决方法:

你需要把它投射到日期,如:

SELECT DATE('2011-02-29') BETWEEN DATE('2011-02-01') AND DATE('2011-03-03')

来自网站:

For best results when using BETWEEN with date or time values, use
CAST() to explicitly convert the values to the desired data type.
Examples: If you compare a DATETIME to two DATE values, convert the
DATE values to DATETIME values. If you use a string constant such as
‘2001-1-1’ in a comparison to a DATE, cast the string to a DATE.

上一篇:mybatis 中between and用法


下一篇:Between Worlds