mysql - 如何在 MySQL 中检查日期时间是否等于明天

标签 mysql date datetime

如果数据 created_at Datetime 列等于明天日期,我想检索 mysql 表数据,例如:

SELECT * FROM sales_order where created_at = tomorrow_date; 

最佳答案

您可以使用以下解决方案,使用 DATEDIFFDATE_ADD :

SELECT * 
FROM sales_order 
WHERE DATEDIFF(created_at, DATE_ADD(CURDATE(), INTERVAL 1 DAY)) = 0;

或仅使用 DATEDIFF 的更简单的解决方案:

SELECT * 
FROM sales_order 
WHERE DATEDIFF(created_at, CURDATE()) = 1

DATEDIFF() returns expr1 − expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation. - from MySQL docs.

关于mysql - 如何在 MySQL 中检查日期时间是否等于明天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49871976/

相关文章:

php - 我应该如何确定 Perl 中时区的下一个夏令时 (DST) 转换?

php - 字段列表中的未知列

php - 从数据库中获取今天的出生日期

sql - 使用 Redshift 转换日期

MySQL 查询自连接最大日期

jquery - 传递给 MVC Action 的 JSON Date 参数始终为 null

javascript - 将数据从可编辑表单保存到数据库

mysql - concat select 不在 where 子句中使用 (mysql)

mysql - 一种将两个mysql查询合并为一个查询的方法

MYSQL查询只需要在group by字段中获取更大的日期值