Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

sql - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...