简体   繁体   English

MS Access 不过滤短日期格式的计算字段

[英]MS Access doesn't filter calculated field in Short Date format

In my database, I have a field with the following calculation:在我的数据库中,我有一个具有以下计算的字段:

AD logon date: IIf([lastLogonDate]>[LLTConverted],[lastLogonDate],[LLTConverted])

I filter it using the following criteria:我使用以下标准对其进行过滤:

<Date()-60

However, when I run the query, it displays dates that are in the last 60 days.但是,当我运行查询时,它会显示过去 60 天内的日期。

In the source file, lastLogonDate and LLTConverted are set to Short Date format.在源文件中,lastLogonDate 和 LLTConverted 设置为短日期格式。 I tried setting the AD logon date field's format manually (via Properties) to Short Date.我尝试手动(通过属性)将 AD 登录日期字段的格式设置为短日期。 I also tried to use the following code:我还尝试使用以下代码:

AD logon date: Format(IIf([lastLogonDate]>[LLTConverted],[lastLogonDate],[LLTConverted]),"dd/mm/yyyy")

Furthermore, in the Properties sheet, I set the Data Type to Date with Time.此外,在属性表中,我将数据类型设置为带时间的日期。 Neither of them worked.他们都没有工作。

Is there another approach I could use?我可以使用另一种方法吗?

EDIT:编辑:

Data before filter:过滤前的数据:

08/01/2021 2021 年 8 月 1 日
30/09/2020 2020 年 9 月 30 日
24/06/2020 2020 年 6 月 24 日
17/06/2020 17/06/2020
20/05/2020 20/05/2020
17/06/2020 17/06/2020
28/02/2020 28/02/2020
07/01/2021 2021 年 7 月 1 日
10/09/2020 2020 年 10 月 9 日
13/11/2019 2019 年 13 月 11 日
07/01/2021 2021 年 7 月 1 日
01/06/2020 2020 年 1 月 6 日
21/05/2020 21/05/2020
25/05/2020 2020 年 5 月 25 日
08/01/2021 2021 年 8 月 1 日
07/01/2021 2021 年 7 月 1 日
07/08/2020 2020 年 7 月 8 日
18/02/2020 2020 年 2 月 18 日
28/02/2020 28/02/2020
25/06/2020 25/06/2020
07/10/2020 2020 年 7 月 10 日
01/04/2019 2019 年 1 月 4 日
07/02/2020 2020 年 7 月 2 日
28/11/2019 28/11/2019
28/10/2020 2020 年 10 月 28 日
18/02/2020 2020 年 2 月 18 日
07/10/2020 2020 年 7 月 10 日

After filter:过滤后:

08/01/2021 2021 年 8 月 1 日
07/01/2021 2021 年 7 月 1 日
10/09/2020 2020 年 10 月 9 日
07/01/2021 2021 年 7 月 1 日
01/06/2020 2020 年 1 月 6 日
08/01/2021 2021 年 8 月 1 日
07/01/2021 2021 年 7 月 1 日
07/08/2020 2020 年 7 月 8 日
07/10/2020 2020 年 7 月 10 日
01/04/2019 2019 年 1 月 4 日
07/02/2020 2020 年 7 月 2 日
07/10/2020 2020 年 7 月 10 日

You are mixing up things.你把事情搞混了。 DateTime values carry no format, only a value. DateTime 值没有格式,只有一个值。

Thus, if fields [lastLogonDate] and [LLTConverted] are true DateTime, filtering with Date()-60 cannot fail.因此,如果字段 [lastLogonDate] 和 [LLTConverted] 为真 DateTime,则使用 Date()-60 进行过滤不会失败。

If it does, your fields are most likely Short Text , and must have a proper format like yyyy-mm-dd, and they must be converted before comparison:如果是这样,您的字段很可能是Short Text ,并且必须具有正确的格式,例如 yyyy-mm-dd,并且必须在比较之前对其进行转换:

AD logon date: DateValue(IIf(DateValue([lastLogonDate]) > DateValue([LLTConverted]), [lastLogonDate], [LLTConverted]))

It seems that there is another solution: if I use the INT function in the original Excel table, then it converts the values from date + time to just date.似乎还有另一种解决方案:如果我在原始 Excel 表中使用 INT function,那么它将值从日期+时间转换为日期。 In Access, then I have to use在Access中,然后我必须使用

IIf([lastLogonDate]>[LLTConverted],[lastLogonDate],[LLTConverted])

instead of代替

DateValue(IIf(DateValue([lastLogonDate]) > DateValue([LLTConverted]), [lastLogonDate], [LLTConverted])) . DateValue(IIf(DateValue([lastLogonDate]) > DateValue([LLTConverted]), [lastLogonDate], [LLTConverted]))

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

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