January 4, 2010 at 12:39 pm
Hi,
I have the following query:
------------------------------------
SELECT
Field1,
Field2,
DATE
FROM
TABLE_NAME
WHERE
DATE <= GETDATE()-2
------------------------------------
I need the "2" to be 2 Business Days. Please help!
January 4, 2010 at 12:54 pm
What are business days? Based on today, was last Friday a business day?
The best way to accomplish this is by using a Calendar table that defines which days are business days.
January 4, 2010 at 1:14 pm
Hi, I meant weekdays. Mon-Fri
January 4, 2010 at 1:37 pm
mannymendieta (1/4/2010)
Hi, I meant weekdays. Mon-Fri
Okay, so based on today (2010-01-04) what would the result of today - 2 be?
January 4, 2010 at 2:21 pm
Lynn Pettis (1/4/2010)
mannymendieta (1/4/2010)
Hi, I meant weekdays. Mon-FriOkay, so based on today (2010-01-04) what would the result of today - 2 be?
Meaning - if today is a weekday do you "count" today (so your query becomes <last friday) or not (so your query would be <last thursday)?
Along the same vein - what if your starting date was NOT a weekday? Does Friday become your "base day" (and the same rules apply) or Monday (and the same rules apply)?
Lots of choices with how such math is set up to work....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
January 4, 2010 at 6:53 pm
As a starting point, you can determine the day of the week for a date using the DATEPART() function. Also, since DATEDIFF() can be used to count weeks, you may want to explore an approach that divides your number of business days by five, calculates the date based on the difference in weeks, and adjusts the final date by adjusting for the extra days (days modulo 5) according to the current day of week.
Please do let us see what you come up with or if this approach (admittedly untested) makes sense.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply