Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Database Date and Time
Message
From
18/01/1999 12:27:08
 
 
To
18/01/1999 08:55:00
General information
Forum:
Microsoft SQL Server
Category:
Database management
Miscellaneous
Thread ID:
00177085
Message ID:
00177240
Views:
44
>What happen if I would like to search for date range query?
>Eg. given 2 dates for any records that are between these
>2 dates. Could you show me some examples on how to achieve
>the results. Excuse me for being a newbie in SQL. Thanks.
>

I've had lots of luck using DATEPART() and breaking the date into to components: day of year and year. The SQL looks ugly but works:

WHERE (DATEPART(dy, t.datefield) >= DATEPART(dy, @LowerBound) AND DATEPART(yy, t.datefield) >= DATEPART(yy, @LowerBound)) AND (DATEPART(dy, t.datefield) <= DATEPART(dy, @UpperBound) AND DATEPART(yy, t.datefield) <= DATEPART(yy, @UpperBound))

Does anyone else have a solution?

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform