{"id":6799,"date":"2013-12-11T00:00:36","date_gmt":"2013-12-11T00:00:36","guid":{"rendered":"http:\/\/craftydba.com\/?p=6799"},"modified":"2016-04-20T01:54:03","modified_gmt":"2016-04-20T01:54:03","slug":"datetime-functions-switchoffset","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=6799","title":{"rendered":"Date\/Time Functions &#8211; SWITCHOFFSET()"},"content":{"rendered":"<p>This is the last 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>It has surely been a-lot of work to write 41 articles on every way to slice and dice dates, times and offsets.<\/p>\n<p>Today, I am going to talk about the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb677244.aspx\">SWTICHOFFSET()<\/a> function.  This function is useful when you want to convert time from one zone to another.  <\/p>\n<p>The function takes a date\/time offset variable as input as well as the new offset value.  It returns a date\/time offset variable in the new zone.<\/p>\n<p>The examples below convert the variable to one zone ahead three hours and one zone behind three hours. <\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"switchoffset() function\">\r\n\/*\r\n   Sample use of function\r\n*\/\r\n\r\n-- Adjust two date time offset variables\r\nSELECT \r\n  SWITCHOFFSET ('1998-09-20 7:45:50.71345 -5:00', '-08:00') as SUB3HRS,\r\n  SWITCHOFFSET ('1998-09-20 7:45:50.71345 -5:00', '-02:00') as ADD3HRS\r\nGO\r\n<\/pre>\n<\/p>\n<p>The output from the test above is listed below. <\/p>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nSUB3HRS                            ADD3HRS\r\n---------------------------------- ----------------------------------\r\n1998-09-20 04:45:50.7134500 -08:00 1998-09-20 10:45:50.7134500 -02:00\r\n<\/pre>\n<\/p>\n<p>In summary, the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb677244.aspx\">SWITCHOFFSET()<\/a> function is useful when you have servers in different time zones and you want to know when something happened in relationship to your zone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the last short articles or tidbits on Transaction SQL date\/time functions. It has surely been a-lot of work to write 41 articles on every way to slice and dice dates, times and offsets. Today, I am going to talk about the SWTICHOFFSET() function. This function is useful when you want to convert time from one zone to another. The function takes a date\/time offset variable as input as well as the new offset value. It returns a date\/time offset variable in the new zone. The examples below convert&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6759,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[814],"tags":[31,940,551,15,1005,29],"class_list":["post-6799","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-very-short-articles","tag-database-developer","tag-date-time-functions","tag-datetimeoffset","tag-john-f-miner-iii","tag-switchoffset","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/6799","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=6799"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/6799\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/media\/6759"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}