﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by J.D. Gonzalez / Article Discussions / Article Discussions by Author  / Function to determine business hours / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 03:30:54 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Function to determine business hours</title><link>http://www.sqlservercentral.com/Forums/Topic410454-220-1.aspx</link><description>I have noticed the same bugs and fixed them in the following way:first I adjust StartDate And EndDate  if they are not whithin bussines hours /*If the start date is after the business hours we will remove the minutes from the StartDate*/  select @StartDate = case when datepart(hh,@StartDate) in (0,1,2,3,4,5,6,7,12,17,18,19,20,21,22,23)	then dateadd(mi,-datepart(mi,@StartDate),@StartDate) else @StartDate end  /*If the End date is after the business hours we will remove the minutes from the EndDate*/  select @endDate = case when datepart(hh,@endDate) in (0,1,2,3,4,5,6,7,12,17,18,19,20,21,22,23)	then dateadd(mi,-datepart(mi,@endDate),@endDate) else @endDate end	then I have changed a bit the while statement while @Cnt &amp;lt; FLOOR(@HoursBetween) And it works perfectly,  thx.</description><pubDate>Tue, 04 May 2010 14:03:49 GMT</pubDate><dc:creator>guzun.allex</dc:creator></item><item><title>RE: Function to determine business hours</title><link>http://www.sqlservercentral.com/Forums/Topic410454-220-1.aspx</link><description>There are several bugs to this formula when dealing with minutes and the @enddate is after the business hours.  Also, there is an issue with identical minutes and the calucation of hours.   The @Cnt needs to be a 1 in the event the difference between the @startdate and @enddate is less than 1 hour.These changes should be incorporated into the code:select @Cnt=case when datediff(mi,@StartDate,@endDate)%60=0 then 0 else 1 endselect @strip = case when datepart(hh,@enddate) in (0,1,2,3,4,5,6,7,12,17,18,19,20,21,22,23)then (60-datepart(mi,@startdate))*.0167  else convert(decimal(9,2),right(@hoursBetween,3)) endthat should get you there!doug</description><pubDate>Sat, 10 Jan 2009 05:52:53 GMT</pubDate><dc:creator>douglas spencer</dc:creator></item><item><title>Function to determine business hours</title><link>http://www.sqlservercentral.com/Forums/Topic410454-220-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Miscellaneous/31471/"&gt;Function to determine business hours&lt;/A&gt;[/B]</description><pubDate>Sat, 13 Oct 2007 18:10:22 GMT</pubDate><dc:creator>J.D. Gonzalez</dc:creator></item></channel></rss>