Reputation: 4692
Does anyone know the range comparison of the BETWEEN
clause? if I have a datetime
datatype, does the BETWEEN
clause compare until hour/minute/second level?
Upvotes: 3
Views: 2205
Reputation: 415690
This:
WHERE datetime_column BETWEEN '2010-08-11' AND '2010-08-12'
is equivalent to
WHERE (datetime_column >= '2010-08-11 00:00:00.000' AND datetime_column <= '2010-08-12 00:00:00.000')
There are two things to note here:
'2010-08-11'
doesn't mean you're checking on an entire day.Upvotes: 4
Reputation: 18325
Saying val BETWEEN @lowVal AND @highVal
is exactly the same as saying @lowVal <= val AND val <= @highVal
, so yes... datetime comparisons include all parts of the date. See here.
Upvotes: 1
Reputation: 344291
It depends on the data type. BETWEEN
returns TRUE
if the value of the test_expression
is greater than or equal to the value of the begin_expression
and less than or equal to the value of the end_expression
(Source).
The following:
BETWEEN date_field '2010-01-01 12:00:00' AND '2010-02-01 12:00:00'
is equivalent to this:
date_field >= '2010-01-01 12:00:00' AND date_field <= '2010-02-01 12:00:00'
Upvotes: 2
Reputation: 602
yes it does, if its the same (down to the millasecond) then it is valid and will assert to true. So will be shown
Upvotes: 5