[TIPS] Calculate the time/date difference in Power Automate / Flow

 [TIPS] Calculate the time/date difference in Power Automate / Flow

Power Automate has an expression called ticks(…). This expression will take a date and calculate the number of ticks for that date. One tick is 100 nanoseconds, starting with the 1st of January 0001 00:00:00. 

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

Date1 - Date2

sub(ticks(Date1), ticks(Date2))

Convert ticks into more readable unit

The result of the subtraction should be then converted into a more understandable number. 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 Date1 and Date2:

div(sub(ticks(Date1),  ticks(Date2)),600000000)

2 comments: