{"id":1652,"date":"2018-03-09T16:21:33","date_gmt":"2018-03-09T21:21:33","guid":{"rendered":"https:\/\/toddbaginski.com\/blog\/?p=1652"},"modified":"2018-06-04T14:45:31","modified_gmt":"2018-06-04T18:45:31","slug":"working-with-local-and-utc-dates-and-times-in-powerapps","status":"publish","type":"post","link":"https:\/\/toddbaginski.com\/blog\/working-with-local-and-utc-dates-and-times-in-powerapps\/","title":{"rendered":"Working with Local and UTC Dates and Times in PowerApps"},"content":{"rendered":"<p>Handling dates and times with Local time and UTC time when you are developing PowerApps can be tricky.\u00a0 Believe me, I know.\u00a0 \ud83d\ude42<\/p>\n<p>&#8220;A man who dares to waste one hour of time has not discovered the value of life.&#8221; <strong>&#8211; Charles Darwin<\/strong><\/p>\n<p>&#8220;A man who dares to waste one hour of time developing PowerApps has not discovered this blog post.&#8221; <strong>&#8211; Todd Baginski<\/strong><\/p>\n<h5 style=\"text-align: center;\">To make reading this blog post as awesome as possible, I highly recommend listening to Pink Floyd\u2019s &#8216;Time&#8217; in another browser window by clicking\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=JwYX52BP2Sk\" target=\"_blank\" rel=\"noopener\">this link<\/a>.<\/h5>\n<p>Alright, enough joking around, here are a couple of things related to Dates and Times to be aware of in PowerApps.<\/p>\n<p>First, in case you never noticed, the Date Picker control in PowerApps allows you to set the <strong>Date time zone<\/strong> property.<\/p>\n<p>Here&#8217;s one set to <strong>UTC time:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1661\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/LocalDatePicker.png\" alt=\"\" width=\"430\" height=\"209\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/LocalDatePicker.png 430w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/LocalDatePicker-300x146.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/LocalDatePicker-260x126.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/LocalDatePicker-50x24.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/LocalDatePicker-144x70.png 144w\" sizes=\"auto, (max-width:767px) 430px, 430px\" \/><\/p>\n<p>Here&#8217;s another set to <strong>Local time:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1662\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/UTCDatePicker.png\" alt=\"\" width=\"434\" height=\"208\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/UTCDatePicker.png 434w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/UTCDatePicker-300x144.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/UTCDatePicker-260x125.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/UTCDatePicker-50x24.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/UTCDatePicker-146x70.png 146w\" sizes=\"auto, (max-width:767px) 434px, 434px\" \/><\/p>\n<p>Depending which value you select, the date and time returned by the control will reflect the Local or UTC date and time.\u00a0 Pay attention to this and make sure you set the property to meet your scenario.<\/p>\n<p>Another thing to be aware of, the connectors that communicate with the Graph API (or any other API), or custom connectors you create, may return Local or UTC times, and they may also expect Local or UTC times as parameters.<\/p>\n<p>Here&#8217;s an example of a date and time value coming back from the Graph API.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1663\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample.png\" alt=\"\" width=\"1031\" height=\"165\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample.png 1031w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample-300x48.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample-768x123.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample-1024x164.png 1024w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample-260x42.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample-50x8.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/GraphDateExample-200x32.png 200w\" sizes=\"auto, (max-width:767px) 480px, (max-width:1031px) 100vw, 1031px\" \/><\/p>\n<p>When you are developing PowerApps, you need to make sure you are always using the appropriate Local or UTC times to ensure all your data makes sense in the PowerApp as well as all the systems it integrates with.<\/p>\n<p>You may also need to convert Local dates and times to UTC dates and times.\u00a0 It all depends on your PowerApp and the connectors it uses.<\/p>\n<p>To make this easier to figure out I created a sample PowerApp that demonstrates how Local and UTC Date Pickers work and also how to use the TimeZoneOffset function to convert Local to UTC time.<\/p>\n<p>Here&#8217;s what it looks like.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1665\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct.png\" alt=\"\" width=\"854\" height=\"478\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct.png 854w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct-300x168.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct-768x430.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct-260x146.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct-50x28.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/02\/DateTimePowerApp50Pct-125x70.png 125w\" sizes=\"auto, (max-width:767px) 480px, (max-width:854px) 100vw, 854px\" \/><\/p>\n<p>You can also convert UTC to Local time pretty easily, but it&#8217;s not demonstrated in the sample PowerApp.\u00a0 You can learn how to do that\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/functions\/function-dateadd-datediff\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Download the sample PowerApp <a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/03\/DateLearningApp_20180308214035.zip\">here.<\/a><\/p>\n<p>Now, quit wasting time and go download it!\u00a0 \ud83d\ude42<\/p>\n<p>Thanks,\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/c-ian-davis\/\" target=\"_blank\" rel=\"noopener\">Ian Davis,<\/a> for working through this with me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Handling dates and times with Local time and UTC time when you are developing PowerApps can be tricky.\u00a0 Believe me, I know.\u00a0 \ud83d\ude42 &#8220;A man who<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":1682,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[104,121],"tags":[10,5,54,45,112],"class_list":["post-1652","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office-365","category-powerapps","tag-custom-development","tag-helpful-code","tag-mobile","tag-o365","tag-powerapps"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/comments?post=1652"}],"version-history":[{"count":15,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1652\/revisions"}],"predecessor-version":[{"id":1681,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1652\/revisions\/1681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media\/1682"}],"wp:attachment":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media?parent=1652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/categories?post=1652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/tags?post=1652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}