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
where 
DAY(datetime_column) = 20 AND 
MONTH(datetime_column) = 12 AND 
YEAR(datetime_column) = 2022

Compare Date in varchar Column

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

Categorized in:

Tagged in: