Business Days using GETDATE()

  • 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!

  • 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.

  • Hi, I meant weekdays. Mon-Fri

  • 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?

  • Lynn Pettis (1/4/2010)


    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?

    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?

  • 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