abatishchev abatishchev - 3 months ago 8x
SQL Question

Compare two DATETIME only by date not time in SQL Server 2008

I have two tables where column

is type of

I have to compare two records only by theirs Date parts (day+month+year), discarding Time parts (hours+minutes+seconds).

How can I dot that?


Use the CAST to the new DATE data type in SQL Server 2008 to compare just the date portion:

IF CAST(DateField1 AS DATE) = CAST(DateField2 AS DATE)