home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 19,031 of 19,505   
   rja.carnegie@gmail.com to Andy   
   Re: Advanced DateDiff Calculation In SQL   
   09 Mar 14 21:32:09   
   
   On Monday, 3 March 2014 20:35:04 UTC, Andy  wrote:   
   > I'm trying to do a calculation on 2 date fields.  I'd like to   
   > get the exact difference in time between 2 dates but I don't   
   > want to include any time if the duration falls over a weekend.   
   > For example, find me the difference in time with the following   
   > but don't include any time after Friday at midnight to Sunday   
   > at midnight.   
      
   I once addressed a similar problem with a user-defined function,   
   but I gather that, as of SQL Server 2005 or thereabouts, there's   
   a high cost to using that.  Also, my requirement was to count   
   whole business-hours hours - or something like that.   
      
   If there is an overhead to using a function and you use it   
   anyway, then there may be not much greater cost in just   
   adding one day at a time to the first date until you pass   
   the second... or one week at a time, and then refine it.   
      
   There's probably something like that on some web page already,   
   but it may not take account of international variation in the   
   definition of "weekday" - and their names - or of the fact that   
   the command "SET DATEFIRST" may have been used.  After all,   
   that exists, presumably someone somewhere wanted to use it.   
      
   So, web pages that come up when you type "SQL Server" and   
   "business days" into Google - with the quote marks -   
   that get into a discussion with visitors leaving comments,   
   is probably going to bring the function @@DATEFIRST into it,   
   basically just to cancel the setting out...   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca