Monday, July 28, 2014

SQL Date Comparison

select case when '2014-07-23 19:00:00' = 'Jul 23 2014 7:00PM' then 1 else 0 end
-- This is string to string comparison

Result will be 0



select case when CAST('2014-07-23 19:00:00' AS DATETIME ) = 'Jul 23 2014 7:00PM' then 1 else 0 end
-- This is datetime to implicit datetime comparison

Result will be 1


select case when '2014-07-23 19:00:00' = CAST('Jul 23 2014 7:00PM' AS DATETIME) then 1 else 0 end
-- This is implicit datetime to datetime comparison

Result will be 1