Calculate Number of working Days in a Given Period

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shilpareddy2787
    New Member
    • Nov 2007
    • 11

    #1

    Calculate Number of working Days in a Given Period

    Hello,

    I have some total values, I want to calculate percenatge of these Total Values.
    I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period.

    How to calculate the Total Number of working Days in a given period . Let us say If i give the period as 08/01/2008 to 08/15/2008, I want total number of working days as 11.

    Please help me
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    Hi,
    Try the following query:

    [code=sql]
    SELECT Count(Date_Colu mn)
    FROM Table_Name
    WHERE Date_Column BETWEEN '08/01/2008' AND '08/15/2008'
    AND Datename(weekda y, Date_Column) NOT IN ('Sunday','Satu rday')

    [/code]


    Thanks

    Comment

    • shilpareddy2787
      New Member
      • Nov 2007
      • 11

      #3
      I don't have any Date column.
      I just want to calculate the Total No. Of Working Days in the Given Period

      Comment

      • deepuv04
        Recognized Expert New Member
        • Nov 2007
        • 227

        #4
        Originally posted by shilpareddy2787
        I don't have any Date column.
        I just want to calculate the Total No. Of Working Days in the Given Period

        Hi,
        Try the following one

        [code=sql]
        Declare @startdate datetime
        Declare @enddate datetime

        Set @startdate = '08/01/2008'
        Set @enddate = '08/15/2008'

        SELECT Count(Date)
        FROM ( Select dateadd(dd,numb er,@startdate) as Date
        from master.dbo.spt_ values
        where master.dbo.spt_ values.type='p' AND dateadd(dd,numb er,@startdate)< =(@enddate)
        ) AS T
        WHERE Datename(weekda y, T.Date) NOT IN ('Sunday','Satu rday')

        [/code]
        Thanks

        Comment

        • bvandale
          New Member
          • Apr 2012
          • 1

          #5
          I found this on another site:

          select @weekDaysInPeri od = (
          DATEDIFF(DAY, @StartDate, @EndDate) + 1
          + (DATEDIFF(DAY, '17530101', @StartDate) + 1) / 7 * 2
          - (DATEDIFF(DAY, '17530101', @EndDate) + 1) / 7 * 2
          - CASE DATEDIFF(DAY, '17530101', @StartDate) % 7
          WHEN 6 THEN 1
          ELSE 0
          END
          - CASE DATEDIFF(DAY, '17530101', @EndDate) % 7
          WHEN 5 THEN 1
          ELSE 0
          END
          )

          Comment

          Working...