Date Range in SQL Query

5 pts.
Tags:
MSSQL
Hi I would like to extract records from Db within a date range. Let's say where the date is between today and last three months. For example today is 6th Dec. Last three months will range till 6th Sep. but I also want it to incldue from 1st of sep till 6th of Dec.

Software/Hardware used:
MS SQL

Answer Wiki

Thanks. We'll let you know when a new response is added.

Sound a bit tricky.. So if I understand you are not looking for just going back say 90 days. You want to go back 3 months regardless of where you are in the current month?? If that is the case,  then extract the current month and – 4 to get your new starting month.

Example:  Dec is month 12 and you want all of Sept (9), Oct(10), Nov(11) as well as current data in Dec.
Then just string together the new month, year if it wraps around and starting day to one. Post your code if you have problems.
One more thing I forgot. For selecting the date ranges in a proper manner, you need to sort them by year/month/day before you set your range parameters.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: