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

SQL Server less than or equal to (<=) date not including last date

I have a what seems to be a simple but odd finding. When I use:

WHERE DateTime >= '2024-04-01' AND DateTime <= '2024-04-30'

This above only gives me up to 04/29, but not 04/30

WHERE DateTime >= '2024-04-01' AND DateTime < '2024-04-30'

This also only gives me up to 04/29, but not 04/30\

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

*And it is definitely not because 04/30 does not have any data, otherwise not need for bothering to post.
04/30 appears when I edit the WHERE to

AND DateTime < '2024-05-01'

And similarly if I use <= ‘2024-05-01’, it also gives me up to 04/30 but not 05/01

Which is weird, why is <= treated the same way as <?

Thank you!

>Solution :

They are not the same. When using <= the value 2024-04-30 is only included if you have a DateTime value of ‘2024-04-30 00:00:00’ exactly. Using < will exclude 2024-04-30 completely. See also How to compare datetime with only date in SQL Server.

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