{"id":193,"date":"2018-10-30T14:56:47","date_gmt":"2018-10-30T14:56:47","guid":{"rendered":"http:\/\/4us2use.at\/?p=193"},"modified":"2018-11-09T16:48:49","modified_gmt":"2018-11-09T16:48:49","slug":"ms-flow-calculating-datetime-difference","status":"publish","type":"post","link":"http:\/\/4us2use.at\/?p=193","title":{"rendered":"MS Flow &#8211; Calculating DateTime Difference"},"content":{"rendered":"<p>Problem:<\/p>\n<p>I needed something like calcDateTimeDiff formula, but wasn&#8217;t available in Flow.\u00a0 The data source in my case was a SharePoint list and I wanted to write the time difference (daily work time) back to the list in a string column.<\/p>\n<p>Solution:<\/p>\n<p>1. calculate the datetime difference in ticks() format &#8211; yes, that&#8217;s the trick!<br \/>\nOne tick = 1 nanosecond<br \/>\nsub(ticks(item()[&#8216;stEnd&#8217;]),ticks(item()[&#8216;dtStart&#8217;]))<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-198\" src=\"http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc1-1.png\" alt=\"\" width=\"1002\" height=\"194\" srcset=\"http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc1-1.png 1002w, http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc1-1-300x58.png 300w, http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc1-1-768x149.png 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>2.\u00a0 Starting the day at 00:00 and add the seconds, then define the output format (1 second = 10.000.000 ns)<br \/>\naddSeconds(&#8217;00:00:00&#8242;,int(div(int(variables(&#8216;testDiffDate&#8217;)),10000000)),&#8217;HH:mm:ss&#8217;)<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-199\" src=\"http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc2-1.png\" alt=\"\" width=\"992\" height=\"365\" srcset=\"http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc2-1.png 992w, http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc2-1-300x110.png 300w, http:\/\/4us2use.at\/wp-content\/uploads\/2018\/10\/DateTimeDiffCalc2-1-768x283.png 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<span id=\"post-ratings-193\" class=\"post-ratings\" data-nonce=\"b0cdcdcb8b\"><img id=\"rating_193_1\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_on.gif\" alt=\"1 Star\" title=\"1 Star\" onmouseover=\"current_rating(193, 1, '1 Star');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_193_2\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_on.gif\" alt=\"2 Stars\" title=\"2 Stars\" onmouseover=\"current_rating(193, 2, '2 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_193_3\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_on.gif\" alt=\"3 Stars\" title=\"3 Stars\" onmouseover=\"current_rating(193, 3, '3 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_193_4\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_on.gif\" alt=\"4 Stars\" title=\"4 Stars\" onmouseover=\"current_rating(193, 4, '4 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_193_5\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_on.gif\" alt=\"5 Stars\" title=\"5 Stars\" onmouseover=\"current_rating(193, 5, '5 Stars');\" onmouseout=\"ratings_off(5, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/> (<strong>2<\/strong> votes, average: <strong>5.00<\/strong> out of 5)<br \/><span class=\"post-ratings-text\" id=\"ratings_193_text\"><\/span><\/span><span id=\"post-ratings-193-loading\" class=\"post-ratings-loading\"><img src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/loading.gif\" width=\"16\" height=\"16\" class=\"post-ratings-image\" \/>Loading...<\/span>\n","protected":false},"excerpt":{"rendered":"<p>Problem: I needed something like calcDateTimeDiff formula, but wasn&#8217;t available in Flow.\u00a0 The data source in my case was a SharePoint list and I wanted to write the time difference (daily work time) back to the list in a string column. Solution: 1. calculate the datetime difference in ticks() format &#8211; yes, that&#8217;s the trick! &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/4us2use.at\/?p=193\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MS Flow &#8211; Calculating DateTime Difference&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/193"}],"collection":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=193"}],"version-history":[{"count":4,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/193\/revisions"}],"predecessor-version":[{"id":202,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/193\/revisions\/202"}],"wp:attachment":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=193"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}