Question: I have a table in SQL Server 2005 which has three columns: 

```
id (int), 
message (text), 
timestamp (datetime)

```

There is an index on timestamp and id.

I am interested in doing a query which retrieves all messages for a given date, say '12/20/2008'. However I know that simply doing where timestamp='12/20/2008' won't give me the correct result because the field is a datetime field. 

Somebody had recommended using the DATEPART function and pulling the year, month, and day out of timestamp and verifying that these are equal to 2008, 12, and 20, respectively. It looks like this would not use the index I have on timestamp and would end up doing a full table scan.

So what is the best way to construct my query so that I am taking advantage of the index that I have created?

Answer: 
```
-- avoid re-calculating @MyDate +1 for every row
DECLARE @NextDay DateTime
Set @NextDay = @MyDate + 1

SELECT 
    -- ...
WHERE [timestamp] >= @MyDate AND [timestamp] < @NextDay

```
BETWEEN does NOT do >=, <. It does >=, <=, as this code proves:

```
declare @low datetime
declare @high datetime
set @low = getdate()
set @high = @low+1

select case when @low between @low and @high then 1 else 0 end, 
    case when @high between @low and @high then 1 else 0 end

```

The result will be 1,1, showing that the = is applied to both bounds.