简体   繁体   中英

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.

In the source file, lastLogonDate and LLTConverted are set to Short Date format. I tried setting the AD logon date field's format manually (via Properties) to Short Date. 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
30/09/2020
24/06/2020
17/06/2020
20/05/2020
17/06/2020
28/02/2020
07/01/2021
10/09/2020
13/11/2019
07/01/2021
01/06/2020
21/05/2020
25/05/2020
08/01/2021
07/01/2021
07/08/2020
18/02/2020
28/02/2020
25/06/2020
07/10/2020
01/04/2019
07/02/2020
28/11/2019
28/10/2020
18/02/2020
07/10/2020

After filter:

08/01/2021
07/01/2021
10/09/2020
07/01/2021
01/06/2020
08/01/2021
07/01/2021
07/08/2020
07/10/2020
01/04/2019
07/02/2020
07/10/2020

You are mixing up things. DateTime values carry no format, only a value.

Thus, if fields [lastLogonDate] and [LLTConverted] are true DateTime, filtering with Date()-60 cannot fail.

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:

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. In Access, then I have to use

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

instead of

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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