I need to get the time difference between two dates in dd/mm/yyyy hh:mm AM/PM format in PowerApps, but I couldn’t do it.
I need to get the result to solve a problem. I read different blogs with different answers, but it does not work. I have watched videos on Youtube – but nothing works.
to do this, you first need to use formatDateTime to convert it to a UTC friendly (ISO 8601) format. you can do it using this expression.
from dd-MM-yyyy hh:mm AM/PM >>> yyyy-MM-ddThh:mm:ss
concat(
substring(variables('EndDateTime'), 6, 4), '-',
substring(variables('EndDateTime'), 3, 2), '-',
substring(variables('EndDateTime'), 0, 2), 'T',
if(equals(substring(variables('EndDateTime'), 17, 2), 'AM'),
concat(substring(variables('EndDateTime'), 11, 5),':00'),
concat(add(int(first(split(substring(variables('EndDateTime'), 11, 5),':'))),12),':',last(split(substring(variables('EndDateTime'), 11, 5),':')),':00')
)
)
Then, you can use this expression to get the time difference in “Minutes”
div(sub(ticks(variables('End Time')), ticks(variables('Start Time'))), 600000000)
Next, you can divide this by 60 to get the difference in hours.
THE FINAL RUN OUTPUT IS AS FOLLOWS:
The dates i used in the sample are 25/03/2001 07:30 AM and 23/07/2024 05:30 PM. I was able to get the actual hours difference at the end which is 204,514 hours as per the verification below.
PLEASE ACCEPT THE SOLUTION IF IT HELPED