MS SQL compare dates?

前端 未结 5 2058
-上瘾入骨i
-上瘾入骨i 2020-12-08 01:30

I have 2 dates (datetimes):

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

Its the same day, just different times. Com

5条回答
  •  庸人自扰
    2020-12-08 02:16

    Use the DATEDIFF function with a datepart of day.

    SELECT ...
    FROM ...
    WHERE DATEDIFF(day, date1, date2) >= 0
    

    Note that if you want to test that date1 <= date2 then you need to test that DATEDIFF(day, date1, date2) >= 0, or alternatively you could test DATEDIFF(day, date2, date1) <= 0.

提交回复
热议问题