sql server - MS SQL compare dates? -


i have 2 dates (datetimes):

date1 = 2010-12-31 15:13:48.593
date2 = 2010-12-31 00:00:00.000

its same day, different times. comparing date1 , date2 using <= doesnt work because of date1 time. date1 <= date2 wrong, should true. can compare them looking @ year, month , day same? sql server 2008.

thanks :)

select case when cast(date1 date) <= cast(date2 date) ... 

should need.

test case

with dates(date1, date2, date3, date4)      (select cast('20101231 15:13:48.593' datetime),                 cast('20101231 00:00:00.000' datetime),                 cast('20101231 15:13:48.593' datetime),                 cast('20101231 00:00:00.000' datetime)) select case          when cast(date1 date) <= cast(date2 date) 'y'          else 'n'        end comparison_with_cast,        case          when date3 <= date4 'y'          else 'n'        end comparison_without_cast   dates  

returns

comparison_with_cast   |  comparison_without_cast y                         n 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -