<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Database Programming: Slaying The Time Zone Conversion Beast (or at least rendering it comatose)</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx</link><description>Schema and code for performing time zone conversions is discussed.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>http://jasonhaley.com/blog/archive/2006/06/10/136624.aspx</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#434841</link><pubDate>Sun, 11 Jun 2006 01:06:19 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:434841</guid><dc:creator>TrackBack</dc:creator><description /></item><item><title>re: Database Programming: Slaying The Time Zone Conversion Beast (or at least rendering it comatose)</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#434926</link><pubDate>Sun, 11 Jun 2006 14:56:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:434926</guid><dc:creator>Mladen</dc:creator><description>Great stuff!&lt;br&gt;&lt;br&gt;I posted a similat post but with less rigouruos demand for accuracy, which i guess it's based on what your app does :)&lt;br&gt;&lt;br&gt;and i think that Daylight savings should be canceled all over the world.&lt;br&gt;it would simplify things, no? :))</description></item><item><title>re: Database Programming: Slaying The Time Zone Conversion Beast (or at least rendering it comatose)</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#435638</link><pubDate>Tue, 13 Jun 2006 20:59:04 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:435638</guid><dc:creator>Ward Pond</dc:creator><description>Thanks, Jason and Mladen..&lt;br&gt;&lt;br&gt;Mladen, why not just have everyone in the world set their clock to the same value? &amp;nbsp;Then the whole problem goes away. &amp;nbsp;:) &amp;nbsp;&lt;br&gt;&lt;br&gt;Hmmm.. &amp;nbsp;But then the old saying, &amp;quot;it's five o'clock somewhere&amp;quot; would have to be revisited.. &amp;nbsp;there are always costs.. &amp;nbsp;that's one of the things that keeps us employed.. :)</description></item><item><title>http://sqlservercentral.com/forums/shwmessage.aspx?forumid=145&amp;messageid=286601</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#437106</link><pubDate>Mon, 19 Jun 2006 03:31:48 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:437106</guid><dc:creator>TrackBack</dc:creator><description /></item><item><title>http://wagnerblog.com/index.php?p=680</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#515311</link><pubDate>Tue, 14 Nov 2006 03:21:11 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:515311</guid><dc:creator>TrackBack</dc:creator><description /></item><item><title>http://sql.ru/subscribe/2006/313.shtml</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#515313</link><pubDate>Tue, 14 Nov 2006 03:22:36 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:515313</guid><dc:creator>TrackBack</dc:creator><description /></item><item><title>http://sqlblog.com/blogs/aaron_bertrand/archive/2008/11/28/troubleshooting-service-broker-through-sql-server-error-logs.aspx</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3162243</link><pubDate>Mon, 01 Dec 2008 07:31:30 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3162243</guid><dc:creator>TrackBack</dc:creator><description /></item><item><title>DST: It's About Time!</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3210947</link><pubDate>Mon, 09 Mar 2009 22:34:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3210947</guid><dc:creator>Jimmy May, Aspiring Geek:  SQL Server Performance, Best Practices, Productivity, etc.&lt;br&gt;&lt;img src="http://img156.imageshack.us/img156/6808/xparentacelogoli1.gif" border="0"/&gt;</dc:creator><description>&lt;p&gt;Daylight Saving Time, DST, has finally returned. We sprung forward yesterday. I love DST! For years here&lt;/p&gt;
</description></item><item><title>As Spring Approaches, a SQL Blogger’s Thoughts Turn to Daylight and Baseball</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3211071</link><pubDate>Tue, 10 Mar 2009 04:33:04 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3211071</guid><dc:creator>Ward Pond's SQL Server blog</dc:creator><description>&lt;p&gt;As we progress towards the Ides of March, one of my best friends-who-I’ve-never-met, Jimmy May , notes&lt;/p&gt;
</description></item><item><title>re: Database Programming: Slaying The Time Zone Conversion Beast (or at least rendering it comatose)</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3253037</link><pubDate>Wed, 10 Jun 2009 16:25:26 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3253037</guid><dc:creator>Iain Johnson</dc:creator><description>&lt;p&gt;Great post - many thanks! It's an almost identical problem to the one I have for a global helpdesk with regional centres. However, I need to calculate two SLA times for a call - the time by when the caller should have been contacted about their issue (typically within an hour) and the time by which the problem should be solved for them (typically within 2 working days).&lt;/p&gt;
&lt;p&gt;The calculation needs to take account of working hours (so a call logged 30 minutes before the helpdesk closes for the day, should be 'contacted' within 30 minutes of the helpdesk opening on it's next working day. I also need to take account of public holidays, i.e. non-working days, other than weekends. I'm surprised you weren't asked to provide that ability too, otherwise the phone will ring on a public holiday but no one is there to answer ? Maybe the phones get switched to a recorded message on such days :)&lt;/p&gt;
</description></item><item><title>re: Database Programming: Slaying The Time Zone Conversion Beast (or at least rendering it comatose)</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3253155</link><pubDate>Wed, 10 Jun 2009 20:57:09 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3253155</guid><dc:creator>Ward Pond</dc:creator><description>&lt;p&gt;@Iain Johnson: Thanks for your kind and thoughtful comments. &amp;nbsp;A few responses for you:&lt;/p&gt;
&lt;p&gt;We do indeed have a Holiday table in our solution, which I omitted from the original post for the sake of brevity and simplicity. &amp;nbsp;It's populated by timezone and country (two things we know about our service centers) and is JOINed into the UDF. &amp;nbsp;It renders time in the same manner as the PhoneQueueSchedule table above.&lt;/p&gt;
&lt;p&gt;It seems to me that, with this modification, you could write three UDFs (or one that takes SLALengthInMinutes as a parameter - better for maintainability) and answer the question, &amp;quot;When will I be past a particular SLA for a particular contact?&amp;quot;.&lt;/p&gt;
&lt;p&gt;Hope this helps! &amp;nbsp;Please write back if there's anything more I can provide.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; -wp&lt;/p&gt;
</description></item><item><title>SLA calculations</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3253660</link><pubDate>Thu, 11 Jun 2009 22:18:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3253660</guid><dc:creator>Iain Johnson</dc:creator><description>&lt;p&gt;Ward, thanks for your response. I should’ve realised you’d simplified matters for readers.&lt;/p&gt;
&lt;p&gt;I can see where I can add in the use of a Holidays table to your UDF, although our holiday table contains just dates, e.g. 2009-12-25 00:00:00. Adding the following WHERE clause seems to work:&lt;/p&gt;
&lt;p&gt;WHERE	dbo.udfTruncateTime(DATEADD(mi, COALESCE(tzdo.UTCOffsetInMinutesWithinInterval, tz.UTCOffset), @UTCTimeToTest))	NOT IN (SELECT HolidayDate FROM dbo.Holiday)&lt;/p&gt;
&lt;p&gt;i.e. where the time being tested (after accounting for the timezone offset) does not fall on a holiday.&lt;/p&gt;
&lt;p&gt;However, I wonder if the above is too simple and wouldn’t be reliable, as you indicated you would JOIN to the Holiday table and from the description of your Holiday table, it sounds like you specify the UTC time for the holiday duration, e.g. for France which is 1 hour ahead of UTC in the winter, Christmas Day would start at 2009-12-25 01:00:00 and have a duration of 1440 minutes. &amp;nbsp;Please could you provide the structure of your holiday table and the JOIN condition used?&lt;/p&gt;
&lt;p&gt;As for the SLA calculation I have to do, do you think it can be done in a set-based way ? That certainly would be awesome. Our current code is procedural rather than set-based, and uses recursion to look for the next working day and split up the SLALengthInMinutes (if spanning working days) to work out the SLA datetime. Whilst I can see how your fnIsPhoneQueueOpen UDF works to determine if a center is open or not at a specified UTC time, not being a SQL whizz, I can’t see how I can write a UDF to return the date &amp;quot;…when will I be past a particular SLA…”. It's asking a lot but if you could provide any more pointers, that would be terrific. I’m intrigued as to the 3 UDF’s you suggested. What would they do ?&lt;/p&gt;
&lt;p&gt;Thanks in advance, Iain.&lt;/p&gt;
</description></item><item><title>re: SLA calculations</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3253759</link><pubDate>Fri, 12 Jun 2009 06:24:45 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3253759</guid><dc:creator>Ward Pond</dc:creator><description>&lt;P&gt;@Iain: Hello again!&lt;/P&gt;
&lt;P&gt;My Holiday table looks the same as PhoneQueueSchedule, except that it has its own unique primary key, a "Holiday" datetime column instead of the day of the week, and the TimeZoneId column is removed. &amp;nbsp;Also, the column names which reference phone queues reference holidays instead.&lt;/P&gt;
&lt;P&gt;We render each holiday as 24 hours (StartMinutesPastLocalMidnight = 0; ClosedLengthInMinutes = 1440 (60 min * 24 hr)). &amp;nbsp;We need to define a record for each phone queue/holiday combination (just as we do for hours of operation), as holidays for us are local observances rather than timezone specific.&lt;/P&gt;
&lt;P&gt;Once all of this set-up work is done, we simply add a call to it to end the query in the UDF as follows:&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;LEFT&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;OUTER&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;JOIN&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;dbo&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Holiday h&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;by PhoneQueue&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;PhoneQueueId&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; pq&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;PhoneQueueId&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;by date (converted to local time; datetimes converted to nvarchar to truncate hh:mm:ss)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;AND&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;CONVERT&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;nvarchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Holiday&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;110&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;CONVERT&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;nvarchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;DATEADD&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;mi&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;COALESCE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;tzdo&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;UTCOffsetInMinutesWithinInterval&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;tz&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;UTCOffset&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;@UTCTimeToTest&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;110&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;by UTC time (translated to "minutes after midnight in queue's local time")&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;AND&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;-- hours (translated to minutes)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:fuchsia;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;DATEPART&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;hh&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;DATEADD&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;mi&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;COALESCE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;tzdo&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;UTCOffsetInMinutesWithinInterval&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;tz&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;UTCOffset&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;@UTCTimeToTest&lt;SPAN style="COLOR:gray;"&gt;))*&lt;/SPAN&gt;60&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;+&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;-- minutes&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;DATEPART&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;mi&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;DATEADD&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;mi&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;COALESCE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;tzdo&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;UTCOffsetInMinutesWithinInterval&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;tz&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;UTCOffset&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;@UTCTimeToTest&lt;SPAN style="COLOR:gray;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;BETWEEN&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;StartMinutesPastLocalMidnight&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;AND&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:gray;FONT-SIZE:10pt;mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;StartMinutesPastLocalMidnight &lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt; h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ClosedDurationInMinutes&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT:normal;MARGIN:0in 0in 0pt;mso-layout-grid-align:none;" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;PhoneQueueId &lt;SPAN style="COLOR:gray;"&gt;IS&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If the outer join succeeds, h.PhoneQueueId is not null, and the query doesn't return data (it shouldn't, because it's a holiday for that phone queue). &amp;nbsp;If the outer join fails, h.PhoneQueueId is null (it's not a holiday), and the query returns data if it otherwise should. &amp;nbsp;Voila!&lt;/P&gt;
&lt;P&gt;You can do similar math with the datetime-related intrinsic functions and this data to determine "what time/date will it be when 120 minutes of work time have elapsed?"&lt;/P&gt;
&lt;P&gt;I know this intuitively, but I've not yet been required to do the work. &amp;nbsp;Your inquiry changes that.&lt;/P&gt;
&lt;P&gt;It's getting pretty late here so I'm not going to attempt anything tonight, but I'll write a new post on that topic just as soon as I have a little time to get creative outside of working hours. *g* &amp;nbsp;Figure by the end of the weekend for sure.&lt;/P&gt;
&lt;P&gt;Thanks for your detailed and stimulating questions. &amp;nbsp;Please let me know if there's anything else you need beyond what we're already discussing.&lt;/P&gt;
&lt;P&gt;Thanks again and all the best!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; -wp&lt;/P&gt;</description></item><item><title>re: SLA calculations</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3253968</link><pubDate>Fri, 12 Jun 2009 14:59:03 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3253968</guid><dc:creator>Iain Johnson</dc:creator><description>&lt;p&gt;Hi Ward, thank you so much for your response. It’s very kind of you to offer to write the SLA calc for me.&lt;/p&gt;
&lt;p&gt;I’ve created the Holiday table you describe, as follows:&lt;/p&gt;
&lt;p&gt;CREATE TABLE [dbo].[Holiday](&lt;/p&gt;
&lt;p&gt;	[HolidayId] [int] NOT NULL IDENTITY(1,1) NOT FOR REPLICATION,&lt;/p&gt;
&lt;p&gt;	[PhoneQueueId] [int] NOT NULL,&lt;/p&gt;
&lt;p&gt;	[Holiday] [datetime] NOT NULL,&lt;/p&gt;
&lt;p&gt;	[StartMinutesPastLocalMidnight] [int] NOT NULL,&lt;/p&gt;
&lt;p&gt;	[ClosedDurationInMinutes] [int] NOT NULL&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;and added a few Holiday records which all have their StartMinutesPastLocalMidnight = 0 and ClosedDurationInMinutes = 1440. I’ve added the LEFT JOIN you give to the end of the SELECT statement and it all works (I had to add a PhoneQueue table too). However, I don’t see why you use:&lt;/p&gt;
&lt;p&gt;BETWEEN h.StartMinutesPastLocalMidnight&lt;/p&gt;
&lt;p&gt;AND h.StartMinutesPastLocalMidnight + h.ClosedDurationInMinutes)&lt;/p&gt;
&lt;p&gt;Instead of just:&lt;/p&gt;
&lt;p&gt;BETWEEN 0 AND 1400&lt;/p&gt;
&lt;p&gt;I suppose your way is more flexible, ie. for half-day holidays perhaps or early closing?&lt;/p&gt;
&lt;p&gt;Incidentally, this UDF is now perfect for another piece of information we calculate – whether a call was logged with the helpdesk “out of hours”, i.e. when it is closed.&lt;/p&gt;
&lt;p&gt;I look forward to your next post. Do you already have a number one fan? :)&lt;/p&gt;
&lt;p&gt;Cheers, Iain.&lt;/p&gt;
</description></item><item><title>re: SLA Calculations</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3254966</link><pubDate>Mon, 15 Jun 2009 16:19:09 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3254966</guid><dc:creator>Ward Pond</dc:creator><description>&lt;p&gt;@Iain: I hope you had a good weekend.&lt;/p&gt;
&lt;p&gt;This &amp;quot;little&amp;quot; task has been a bit more effort than I thought it would be, but the good news is that the only real task I have left is to integrate Holiday processing into my sample.&lt;/p&gt;
&lt;p&gt;I don't know exactly when that's going to get done. &amp;nbsp;I've got a very busy week ahead of me.. &amp;nbsp;but this project is definitely under my skin..&lt;/p&gt;
&lt;p&gt;I don't want to make any rash promises, but I certainly hope I won't be more than a couple of days.&lt;/p&gt;
&lt;p&gt;Thanks for your patience.. &amp;nbsp;and the brainteaser!&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; -wp&lt;/p&gt;
</description></item><item><title>http://sqlblog.com/blogs/aaron_bertrand/archive/2008/11/28/troubleshooting-service-broker-through-sql-server-error-logs.aspx</title><link>http://blogs.technet.com/wardpond/archive/2006/06/09/database-programming-slaying-the-time-zone-conversion-beast-or-at-least-rendering-it-comatose.aspx#3287860</link><pubDate>Tue, 20 Oct 2009 11:34:21 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3287860</guid><dc:creator>TrackBack</dc:creator><description /></item></channel></rss>