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. I love working with .NET based CMS, eCommerce solutions, .NET Core, DevOps, and Cloud computing. I am a Certified Episerver CMS developer, MCSD (Microsoft Certified Solution Developer) and MCP in Azure application development. I spend my free time with my family and reading books. You can contact me on [email protected]

View all posts

Leave a Reply

Your email address will not be published.