Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date comparisons
Message
From
17/06/2004 13:10:04
 
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00914601
Message ID:
00914678
Views:
9
Joe,

>between @logdate and @logdate2", where @logdate2 is @logdate + 1

One gotcha with this is that the BETWEEN clause is all inclusive, so that, in your example, this would include midnite of the following day, which is typically not what you want. That's why I said in my reply to use >= and < rather than BETWEEN.

~~Bonnie


>Short and sweet. SQL datetime fields always return a full date time. Which is a double sided sword.
>
>While searching for all records on a particular day a where clause is used like "where logdate = @logdate", when they are passing @logdate as '01/01/2004'. '01/01/2004' really means '01/01/2004 00:00:00.000' and will not return data for the complete day.
>
>The problem can be solved by using the between clause. The where clause for such a query should be "where logdate between @logdate and @logdate2", where @logdate2 is @logdate + 1. The between clause can make use of an index if it exists, where using a convert function like "where convert(varchar,logdate,101) = @logdate" would not and it would slow down the query.
>
>HTH,
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform