Here is my code:
DECLARE @d1 DATETIME DECLARE @d2 DATETIME SET @d1 = '2015-01-01 00:00:00' SET @d2 = '2015-12-31 23:59:59.999' SELECT CASE WHEN ('2016-01-01 00:00:00' BETWEEN @d1 AND @d2) THEN 'is between' ELSE 'not between' END AS BetweenOrNotBetween
The date specified here is 1 ms later than the range of the BETWEEN function, but on my SQL Server 2008 instance, the result is 'between' , not expected > 'not between' ...
Is this a mistake, or is it a necessary compromise in design for some reason I donβt see?
And yes, as soon as I add at least half a second after midnight 2016-01-01, I get the expected result 'not between .
source share