1 2 Previous Next 15 Replies Latest reply on Jan 15, 2018 7:09 AM by Mohammad Naveed

    Calculating Exact Business day using Time based

    Mohammad Naveed

      Hi All,

       

      i am stuck in calculating Business day based on time , below is the SQL query which i am using currently for my project and its working perfectly in SQL Server however when i using same in Tableau its showing an error as "Datediff(string,integer,datetime) error"

       

      can anyone please guide me on this.

       

      Sql Query

      [Code]

      declare @StartDate datetime, @EndDate datetime

       

      select @StartDate = '1/11/2017  3:08:25 PM',@EndDate='1/9/2018  10:40:21 PM'

       

      Select convert(decimal(10,2),(cast(Datediff(second,@StartDate, @EndDate) as decimal(10,2)))/86400 )

      - (DATEDIFF(wk,@StartDate, @EndDate)*2) --Subtact 2 days for each full weekend

        - (1-SIGN(DATEDIFF(dd,6,@StartDate)%7)) --If StartDate is a Sunday, Subtract 1

      - (1-SIGN(DATEDIFF(dd,5, @EndDate)%7)) --If EndDate is a Saturday, Subtract 1

      [/code]

        1 2 Previous Next