I want to do a query with dates this is my sample tsql:
select * from Bookings where StartTime = \'2/15/2014\'
the starttime has value \'2/15/2
The best way to do this is with a simple comparison:
select *
from Bookings
where StartTime >= cast('2014-02-15' as date) and StartTime < cast('2014-02-14' as date);
This is the safest method of comparison, because it will take advantage of an index on StartTime
. This property is called "sargability".
In SQL Server, casting to a date
should also be sargable, so you could also do:
select *
from Bookings
where cast(StartTime as date) = cast('2014-02-15' as date) ;