mysql - 在MySQL上获取两个日期之间的数据

标签 mysql date between

如何获取两个日期之间的值。

我想获取 2010-01-02 和 2010-01-04 之间的值。

示例:

Value DateTime
A     2010-01-01 14:55:12
B     2010-01-02 14:55:12
C     2010-01-03 14:55:12
D     2010-01-04 14:55:12
E     2010-01-05 14:55:12

谢谢!

最佳答案

看看

expr BETWEEN min AND max

If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise it returns 0.

/

For best results when using BETWEEN with date or time values, you should 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 - 在MySQL上获取两个日期之间的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2716336/

相关文章:

mysql - mysql 查询的正则表达式?

php - Laravel 无法删除或更新父行 : a foreign key constraint fails

php - 异常 'PDOException',消息为“SQLSTATE[HY093] : Invalid parameter number: number of bound variables does not match number of tokens”

c - 从特定时区获取日期 - C

python2.7在virtualenv中安装MySQL-python错误 "failed with exit status 2"

Java 解析季度日期的最佳方法

javascript - 使用 getMonth() 获取不同的输出

使用变量和之间的 SQL 替代 IN 运算符

Mysql 子查询之间

Python - 正则表达式获取括号之间的数字