{"id":34,"date":"2016-09-07T13:25:00","date_gmt":"2016-09-07T13:25:00","guid":{"rendered":"\/colin\/morethanfour\/post\/Converting-a-TIMESTAMP-WITH-TZ-in-UTC-to-Central"},"modified":"2016-09-07T13:25:00","modified_gmt":"2016-09-07T13:25:00","slug":"converting-a-timestamp-with-tz-in-utc-to-central","status":"publish","type":"post","link":"https:\/\/spacefold.com\/colin\/morethanfour\/2016\/09\/07\/converting-a-timestamp-with-tz-in-utc-to-central\/","title":{"rendered":"Converting a TIMESTAMP WITH TZ in UTC to Central"},"content":{"rendered":"<p>At ABACAB we have &#8211; very correctly &#8211; a TIMESTAMP WITH TIME ZONE column called ONLINE_ENROLLMENT_TIME that has been populated &#8211; via an ETL process &#8211; with values in UTC.<\/p>\n<p>This is good, because it is a completely unambiguous value. Oh, if only all our date times were stored this way.<\/p>\n<p>Unfortunately, the convention up until now has been:<\/p>\n<ul>\n<li>assume date times are in Central time zone<\/li>\n<li>convert to integer &#8220;date key&#8221; and &#8220;time key&#8221; data types (primary key for date and time dimensions).<\/li>\n<\/ul>\n<p>This loses any time zone information, which is not great. It means that all client processes using this data also need to assume Central time zone.<\/p>\n<p>The following SQL takes our time zone-aware column and transforms it:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\"><span style=\"color: #0000ff\">select<\/span><br>   ID,<br>   ONLINE_ENROLLMENT_TIME,<br>   (ONLINE_ENROLLMENT_TIME <span style=\"color: #0000ff\">at<\/span> <span style=\"color: #0000ff\">time<\/span> <span style=\"color: #0000ff\">zone<\/span> <span style=\"color: #006080\">'US\/Central'<\/span>)                         <span style=\"color: #0000ff\">as<\/span> ONLINE_ENROLLMENT_TIME_C,<br>   trunc( <span style=\"color: #0000ff\">cast<\/span>( (ONLINE_ENROLLMENT_TIME <span style=\"color: #0000ff\">at<\/span> <span style=\"color: #0000ff\">time<\/span> <span style=\"color: #0000ff\">zone<\/span> <span style=\"color: #006080\">'US\/Central'<\/span>) <span style=\"color: #0000ff\">as<\/span> <span style=\"color: #0000ff\">DATE<\/span> )) <span style=\"color: #0000ff\">as<\/span> ONLINE_ENROLLMENT_DATE<br><span style=\"color: #0000ff\">from<\/span> ZYXX.D_Person<br><span style=\"color: #0000ff\">where<\/span> ONLINE_ENROLLMENT_TIME<br><span style=\"color: #0000ff\">is<\/span> <span style=\"color: #0000ff\">not<\/span> <span style=\"color: #0000ff\">null<\/span>;<\/pre>\n<p><\/div>\n<p>Results:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"display: inline\" alt=\"image\" src=\"http:\/\/www.spacefold.com\/colin\/morethanfour\/wp-content\/uploads\/image_11.png\" width=\"629\" height=\"118\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>At ABACAB we have &#8211; very correctly &#8211; a TIMESTAMP WITH TIME ZONE column called ONLINE_ENROLLMENT_TIME that has been populated &#8211; via an ETL process &#8211; with values in UTC. This is good, because it is a completely unambiguous value. Oh, if only all our date times were stored this way. Unfortunately, the convention up [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-oracle","post-preview"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}