简体   繁体   English

查找两个日期之间的记录MySQL

[英]Find a record between two dates MySQL

I am attempting to find records in my DB that's end_date is within 24 hours of the current time. 我正在尝试在数据库DB中找到end_date在当前时间的24小时内的记录。

Here is the query I am currently running 这是我当前正在运行的查询

select *
FROM record r
WHERE NOW() BETWEEN r.end_date AND DATE_ADD(r.end_date, INTERVAL -1 DAY);

This doesn't bring back any of the records with an end_date within 24 hours, am I using the DATE_ADD function wrong? 这不会在24小时内带回任何具有end_date的记录,我使用DATE_ADD函数是否错误?

I think this is what you need: 我认为这是您需要的:

select *
FROM record r
where
r.end_date >= date_add(now(), INTERVAL -1 DAY)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM