gpt4 book ai didi

带有日期的运算符之间的mysql

转载 作者:行者123 更新时间:2023-11-29 01:18:17 25 4
gpt4 key购买 nike

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

这是返回 1。我认为 between 不考虑闰年。我想听听您对此的看法?

[编辑]
SELECT DATE( '2010-04-31' ) 返回 NULL;
但是 select str_to_date('2010-04-31', '%Y-%m-%d') 正在重新调整日期。

为什么?

谢谢地点

最佳答案

你需要像这样投它到日期:

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.

关于带有日期的运算符之间的mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com