Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

How to calculate difference between two times in Power Automate

Posted on February 6, 2022April 6, 2022 by Tom

“I’ve got two times, the task start time and end time, how do I calculate a difference in minutes or hours with Power Automate?”


One of the features missing in Power Automate is a calculation of a difference between two dates / times. There’re many operations with date, you can calculate a date, you can format a date, but you can’t easily calculate a difference. To do that you’ll need a combination of expressions, and that’s what this post is about.

Calculate the number of ticks

As already explained in the post on Excel based reminders, Power Automate has an expression called ticks(…). This expression will take a date and calculate a number of ticks for that date. One tick is 100 nanoseconds, starting with 1st of January 0001 00:00:00. For example, 6th of February 2020 at 19:28 will return 637797689122217300 ticks.

When you calculate a difference between two dates / times, you must get ticks for both of the dates, e.g.

today - yesterday
ticks(today) - ticks(yesterday)
ticks(utcNow()) - ticks(addDays(utcNow(),-1))

Once you have the two numbers of ticks, you can subtract one from the other with the sub(…) expression.

sub(ticks(utcNow()),ticks(addDays(utcNow(),-1)))

= 864000000000

Note: if you end up with a negative number, you should switch the two dates in the expression.

Convert ticks into more readable unit

The result of the subtraction should be then converted into a more understandable number. You don’t want to show users the difference in billions. Use the div(…) expression to divide the number by a number representing the desired unit.

Divide byTo get
864000000000days
36000000000hours
600000000minutes
10000000seconds

For example, to get the number of minutes between yesterday and today:

div(sub(ticks(utcNow()),ticks(addDays(utcNow(),-1))),600000000)
Power Automate calculate difference times

Summary

To calculate a difference between two dates / times in Power Automate, you must combine multiple expressions. Calculate the number of ticks for each date, and then divide it by a number to get the desired unit. Start from 100 nanoseconds (1 tick) and divide it by a number big enough to get the days/hours/minutes.

And if you’d like to get the result as a decimal number, apply float(…) on one of the numbers.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

10 thoughts on “How to calculate difference between two times in Power Automate”

  1. Steve Myles says:
    April 27, 2022 at 8:13 am

    Tom,
    on a similar topic I am trying to covert an Excel Time only column to Sharepoint time only column with power automate.
    I can do this for a date only using technique described here

    https://normyoung.ca/2020/07/20/import-excel-data-into-an-existing-sharepoint-list-using-power-automate/

    Can you suggest how to modify this for a time only column

    Thanks
    Steve

    Reply
  2. Steve Myles says:
    April 28, 2022 at 11:55 am

    Figured it out

    formatDateTime(variables(‘varStartTime’),’HH:mm tt’)

    Reply
    1. Tom says:
      May 3, 2022 at 7:47 pm

      Hello Steve,
      I’m glad that you solved it, thank you for sharing the solution.

      Reply
  3. Paul says:
    September 8, 2022 at 10:06 pm

    Nice write up Tom, solved my problem right away.

    Reply
  4. Pingback: Chris Webb's BI Blog: Calling The Power BI Enhanced Refresh API From Power Automate, Part 6: Cancelling Dataset Refreshes Chris Webb's BI Blog
  5. Iron Arm says:
    October 6, 2022 at 8:48 pm

    Power Automate actually does have a “dateDifference” function under expressions. But it returns it in time format. Ex: 00:01:57.8418729

    Reply
    1. Tom says:
      October 14, 2022 at 10:28 am

      Hello Iron,
      I noticed that there’s this new expressions, but I don’t like the result format. I’d much prefer if they allowed you to enter a 3rd parameter with a unit, e.g. dateDifferece(…,…, ‘seconds’)

      Reply
  6. Pingback: Playing with Power Automate and Calendar events – rakhesh.com
  7. Rachayeeta Mallik says:
    November 29, 2022 at 3:26 pm

    How to calculate the difference between two dates excluding the weekend

    Reply
    1. Tom says:
      December 5, 2022 at 8:13 pm

      Hello Rachayeeta,
      I don’t know, I never needed that.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes