[英]MS-Access SQL Query - Filtering by date
I am trying to write up a Microsoft Access query that will return all of the data in a table where the assigned "Due By" date is within a day. 我正在尝试编写一个Microsoft Access查询,该查询将返回表中分配的“到期日”日期在一天之内的所有数据。
Meaning, when I come into the office in the AM, I should be able to run this query to see what was due yesterday and what is due today. 意思是,当我进入AM的办公室时,我应该能够运行此查询以查看昨天到期和今天到期。 Here is an example of the data:
这是数据示例:
| ID | JobName | DueBy |
|----|-------------------------|-----------|
| 1 | Sergio Pizza | 5/5/2018 |
| 2 | Hopkins Hospital | 9/1/2018 |
| 3 | Perry Hall High School | 9/25/2018 |
| 4 | Parkville High School | 9/24/2018 |
| 5 | Jim's House | 9/24/2018 |
My current query is: 我当前的查询是:
SELECT tblBid.*
FROM tblBid
WHERE (((tblBid.Due_By)>=(Now()-2)));
Which works in returning the correct dataset: 哪个可以返回正确的数据集:
| ID | JobName | DueBy |
|----|-------------------------|-----------|
| 3 | Perry Hall High School | 9/25/2018 |
| 4 | Parkville High School | 9/24/2018 |
| 5 | Jim's House | 9/24/2018 |
However, why do I need to write NOW()-2 and not NOW()-1? 但是,为什么我需要写NOW()-2而不是NOW()-1? Why do I have to go back two days?
为什么我必须回去两天? When I write NOW()-1 I only get ID 3 for Perry Hall High School
当我写NOW()-1时,我只获得佩里·霍尔高中的ID 3
Thank you! 谢谢!
您正在使用Now()
函数,该函数返回当前日期和时间,表中的日期没有时间部分使其成为该日期的12AM,因此在Now() - 1
,您需要使用Date()
函数返回12AM的日期,然后可以将其用作Date() - 1
Use DateDiff : 使用DateDiff :
SELECT tblBid.*
FROM tblBid
WHERE DateDiff("d", tblBid.Due_By, Date()) Between 1 and 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.