Compare dates in SQL

A lot of times we come across issues comparing dates in SQL. There are a few scenarios below

Compare dates in the DateTime Column

Select * from EMP
WHERE datetime_column >= '20221220 00:00:00.000'
AND datetime_column < '20221221 00:00:00.000'

Compare Day Year Month separately in DateTime

Select * from EMP
DAY(datetime_column) = 20 AND 
MONTH(datetime_column) = 12 AND 
YEAR(datetime_column) = 2022

Compare Date in varchar Column

Select * from EMP
convert(date,vDate,101) = '12/20/2020'

About the author

Naveed Ul-Haq

I am a UK-based Technical Architect, Founder & Technology Evangelist. I'm Optimizely MVP & Optimizely SME on Content Cloud and Commerce Cloud. I love working on .NET-based CMS, eCommerce solutions, .NET Core, DevOps, and Cloud computing. I'm also a Certified Optimizely Content Cloud Developer, Certified Optimizely Commerce Cloud developer, Optimizely B2B Commerce developer and Microsoft Certified Professional in Azure application development. I spend my free time with my family and reading books. You can contact me at

View all posts

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *