|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, March 25, 2013 9:57 AM
Points: 22,
Visits: 77
|
|
Hello,
I need to write a query that returns a result set that is within the past 4 weeks and 3 business days. For example, the result set for today would return everything from Feb 6th forward. (Date of this post was March 11).
I have the second part but I am not sure how to include the 3 days. Any help would be appreciated.
select dateadd(week,-4,getdate());
-Dave
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 10:39 AM
Points: 2,556,
Visits: 4,398
|
|
David Mando (3/11/2013) Hello,
I need to write a query that returns a result set that is within the past 4 weeks and 3 business days. For example, the result set for today would return everything from Feb 6th forward. (Date of this post was March 11).
I have the second part but I am not sure how to include the 3 days. Any help would be appreciated.
select dateadd(week,-4,getdate());
-Dave
4 calendar weeks Monday to Friday is possible but for "3 business days" you will need a calendar table, as there is no universal definition for the "business day". For example, today, 11th March 2013, is business day in UK, but bank holiday in Victoria - state of Australia (local 1st May !).
_____________________________________________ "The only true wisdom is in knowing you know nothing" "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!" (So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, March 25, 2013 9:57 AM
Points: 22,
Visits: 77
|
|
Thanks so much for your quick response.
How would I write this query if it is just (- 4 weeks and 3 days)?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 10:39 AM
Points: 2,556,
Visits: 4,398
|
|
Calendar weeks or working weeks? What is your definition of a week? Is it Monday To Friday? Is it Monday to Sunday? Is it Sunday to Saturday? Or may be even (as in some middle-east countries) Saturday to Wednesday?
_____________________________________________ "The only true wisdom is in knowing you know nothing" "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!" (So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 3:56 PM
Points: 1,324,
Visits: 1,778
|
|
David Mando (3/11/2013) Thanks so much for your quick response.
How would I write this query if it is just (- 4 weeks and 3 days)?
select dateadd(day, -3, dateadd(week,-4,getdate()));
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|