Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
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.

3 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

Leave a Reply Cancel reply

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

NOW AVAILABLE:

The Ultimate Power Automate expressions cheat sheet
Spend your time thinking about what the flow should do, not how to do it!

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.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • How to create a new SharePoint list column with Power Automate flowMay 22, 2022
  • How to combine expressions in your Power Automate flowsMay 18, 2022
  • Import Planner tasks with checklists into various buckets (Power Automate)May 15, 2022
  • How to get notified when Planner task was reassigned (Power Automate)May 11, 2022
  • How to extract value from XML using Power Automate flowMay 8, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme