>>Consider the following select statement:
>>
>>SELECT [Id]
>>FROM [MyTable]
>>WHERE YEAR(DateField) = YEAR(@DateField) AND
>> MONTH(DateField) = MONTH(@DateField) AND
>> DAY(DateField) = DAY(@DateField)
>>
>>
>>I want to select the records that have the same date as the parameter, but I do not care about the time part of the field or parameter.
>>Is there another (better) way of doing this?
>>
>>Thanks,
>>Einar
>
>
>DECLARE @myDate datetime
>set @myDate = convert(varchar(8),@DateField,112)
>
>select [id] from [myTable] WHERE DateField between @myDate AND @myDate + 1
>
Cetin
Cetin,
this solution has a tiny bug : the next day midnight precise is selected also, and Murphy is never far away ...
As a solution use Dateadd(second,86399, @myDate) as enddate. 86399 = 86400 seconds in a day minus 1. But even here, the last millisecond of the day isn't selected :-(