将日期添加到当前日期mysql

时间:2022-10-28 22:41:44

I have to find out what items in my warehouse are expiring in next 30 days. I wrote the following query

我必须找出我仓库中的哪些物品在接下来的30天内到期。我写了以下查询

SELECT ItemName, ExpirationDate, 
FROM table 
WHERE ExpirationDate BETWEEN DATE_ADD(SYSDATE(), INTERVAL 30 DAY) and SYSDATE()

I have also tried CURDATE(). ExpirationDate is stored as 'DATE' The query doesn't return any results. I know for sure that there are items expiring in next 30 days. I've also tried giving a large number as INTERVAL 30000 DAY too. I do not get any results.

我也尝试过CURDATE()。 ExpirationDate存储为“DATE”查询不返回任何结果。我确信有些物品会在接下来的30天内到期。我也尝试过大量的INTERVAL 30000 DAY。我没有得到任何结果。

Thanks

1 个解决方案

#1


2  

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

Mysql is looking for the first item in the BETWEEN clause to be the lower value, and the second value to be the higher value.

Mysql正在寻找BETWEEN子句中的第一项为较低值,第二项值为较高值。

SELECT ItemName, ExpirationDate FROM table 
WHERE ExpirationDate BETWEEN SYSDATE() AND DATE_ADD(SYSDATE(), INTERVAL 30 DAY);

#1


2  

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

Mysql is looking for the first item in the BETWEEN clause to be the lower value, and the second value to be the higher value.

Mysql正在寻找BETWEEN子句中的第一项为较低值,第二项值为较高值。

SELECT ItemName, ExpirationDate FROM table 
WHERE ExpirationDate BETWEEN SYSDATE() AND DATE_ADD(SYSDATE(), INTERVAL 30 DAY);