Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ms Access Date function not passing in LIKE query

I want to query records from the access database that matches the current date (system date)

The following query works fine if I enter the date literally.

SELECT SUBJECT, TYPE, CH_NO, TEST_NAME, TEST_CODE, SDATE, ID
FROM MCQS_PAPER
WHERE [SDATE] ALIKE "%5/14/2022%"

I have added the Date() function in the criteria to avoid manual work, but it’s not returning any records.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT SUBJECT, TYPE, CH_NO, TEST_NAME, TEST_CODE, SDATE, ID
FROM MCQS_PAPER
WHERE [SDATE] ALIKE "% Date() %"

Why does the date function not work?

>Solution :

Comparing a date/time value with a string is wrong. You can test a date/time value (e.g. 05/14/2022 11:15 AM) against current date (e.g. 05/14/2022) like so:

WHERE [SDATE] >= Date()
AND   [SDATE] < DateAdd("d", 1, Date())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading