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?
Solved! Go to Solution.
@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 😁 ).
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'])
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)
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'))
which gives this result when the flow runs and you can use the output of that for whatever other actions you need.
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 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 😁 ).
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'])
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)
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'))
which gives this result when the flow runs and you can use the output of that for whatever other actions you need.
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.
@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!