Exclude weekend hours from datediff() function

  • Hello,

    I want to get a total amount of hours for a date range, but I want to exclude any weekend hours from this? So, I want to do it all on one select statement as shown below. I'm stuck on the part of how to get only the weekend hours for the date range so I can subtract it from the datediff function. I have looked online, but nothing works. Any help is appreciated. Thanks.

    declare @startdate datetime, @enddate datetime

    set @startdate = '1/1/2016'

    set @enddate = 1/30/206'

    select datediff(hh, @startdate, @enddate) - (only weekend hours here)

    from table1

  • this may give you a few ideas

    http://www.sqlservercentral.com/Forums/Topic1440451-392-1.aspx

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • Just remember that you might want to consider holidays as well. That's only achievable from a holidays or calendar table.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply