web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How do we calculate th...
Power Automate
Answered

How do we calculate the difference between two dates and times in power automate?

(0) ShareShare
ReportReport
Posted on by 4

I tried to get the difference between two dates and times using Power automate. But the output only comes individually in Days or Hours or Minutes or Seconds.

 

We need the below output in Hours and minutes (HH: mm) using power automate:

Suppose, if we subtract from (End Date & Time) 20/11/2022 13:05 to (Start Date & Time) 20/11/2022 01:30.

Output must come in the format "13:35" (13 hours, 35 minutes).

 

Any help please?

Categories:
I have the same question (0)
  • Verified answer
    RobElliott Profile Picture
    10,333 Super User 2025 Season 2 on at

    @Akhlaq unlike with Power Apps, with Power Automate there is no datediff function so we need to calculate the difference with a series of compose actions. I have a list with date/time columns called Start and End and I've added the date and times you put into your post (although the correct difference is 11 hours 35, not 13 hours 35 😁 ).
    0-SP-List.png

     

    1-Flow.png

     

    I've got the item from Sharepoint and there then need to be 2 compose actions using ticks. The first one, ticksStart, uses the expression ticks(outputs('Get_item')?['body/Start'])

     

    The second, ticksEnd, uses the expression ticks(outputs('Get_item')?['body/End'])

    2-Flow.png

     

    Next, another compose action calculates the difference in minutes with the expression 
    div(div(mul(sub(outputs('ticksEnd'), outputs('ticksStart')), 100), 1000000000), 60)

     

    Next, the difference in hours is calculated with another expression
    div(outputs('DifferenceMinutes'),60)

     

    3-Flow.png

     

    To make sure that the minutes part of the result is returned as minutes and not as a percentage we need to use the mod function in another compose with the expression
    mod(outputs('DifferenceMinutes'),60)

     

    The result in the format hh:mm is created with yet another compose action using the expression
    concat(outputs('DifferenceHours'),':',outputs('Mod'))

     

    4-Flow.png

     

    which gives this result when the flow runs and you can use the output of that for whatever other actions you need.
    5-Result.png

     

    Rob
    Los Gallardos
    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

     

  • Akhlaq Profile Picture
    4 on at

    @RobElliott Thanks for the solution. I used your solution but got the same formatting issue i.e (HH: mm required). For example (06:56), if we calculate the difference between two dates and times, i.e from 21-11-2022 22:00 to 21-11-2022 20:00. After calculation, the output came in the format "2:0". Please see the below screenshot for your reference. The output should be "02:00". 

    Thanks!

     

    Akhlaq_1-1669048736474.png

     

     

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard