{"id":6602,"date":"2013-11-21T00:00:13","date_gmt":"2013-11-21T00:00:13","guid":{"rendered":"http:\/\/craftydba.com\/?p=6602"},"modified":"2016-04-20T17:15:02","modified_gmt":"2016-04-20T17:15:02","slug":"datepart-function-time-zone-offset","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=6602","title":{"rendered":"DATEPART() Function \u2013 Time Zone Offset"},"content":{"rendered":"<p>I am decisive to write another short articles or tidbits on Transaction SQL <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ms186724.aspx\">date\/time functions<\/a>. <\/p>\n<p>Most, if not all, modern day computer systems collect data which contains dates and times.  <\/p>\n<p>Not only is it important to know when a sales order came in, but we should fulfill the request using some type of queue (<a href=\"http:\/\/en.wikipedia.org\/wiki\/LIFO_(computing)\">LIFO<\/a>).  If if was a stack (<a href=\"http:\/\/en.wikipedia.org\/wiki\/FIFO\">FIFO<\/a>) implementation, the first person may never get his order!<\/p>\n<p>Today, I will be exploring the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ms174420.aspx\">DATEPART()<\/a> function.  This function has 15 different input parameters that can be passed to change the resulting output.  <\/p>\n<p>In short, the function takes a date part and date time variables as input returns the part that you want as an integer.  I will be concentrating on how to extract the time zone offset (TZ) in this article.  <\/p>\n<p>The examples below are sample calls to the function.  The inputs puts are valid date, null value and a empty string.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"datepart() function - Time Zone Offset\">\r\n--\r\n--  Functions to get date and time parts as INT\r\n-- \r\n\r\n-- Time Zone Offset\r\nSELECT \r\n  SYSDATETIMEOFFSET() AS FULL_DATE4,\r\n  DATEPART(TZ, SYSDATETIMEOFFSET())\/60 AS TZ_OFFSET_INT,\r\n  DATEPART(TZ, NULL) AS TZ_OFFSET_NULL,\r\n  DATEPART(TZ, '') AS TZ_OFFSET_EMPTY\r\nGO\r\n\r\n<\/pre>\n<\/p>\n<p>The output from the above test is listed below.  Please note that a empty string returns 0 minute offset from GMT or UTC.<\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nFULL_DATE4                         TZ_OFFSET_INT TZ_OFFSET_NULL TZ_OFFSET_EMPTY\r\n---------------------------------- ------------- -------------- ---------------\r\n2013-12-03 16:31:46.9757820 -05:00 -5            NULL           0\r\n\r\n<\/pre>\n<\/p>\n<p>In as nutshell, pass the time zone parameter to extract the offset in minutes from the date time variable.  The the example above, I divided by 60 minutes to convert to an offset in hours.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am decisive to write another short articles or tidbits on Transaction SQL date\/time functions. Most, if not all, modern day computer systems collect data which contains dates and times. Not only is it important to know when a sales order came in, but we should fulfill the request using some type of queue (LIFO). If if was a stack (FIFO) implementation, the first person may never get his order! Today, I will be exploring the DATEPART() function. This function has 15 different input parameters that can be passed to&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6486,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[814],"tags":[31,940,608,15,979,29,980],"class_list":["post-6602","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-very-short-articles","tag-database-developer","tag-date-time-functions","tag-datepart","tag-john-f-miner-iii","tag-timezone","tag-tsql","tag-tz"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/6602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6602"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/6602\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/media\/6486"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}