How to substract two datetime objects in Power Automate

Substracting dates – Can it be any simpler than this? Well quite not when it comes to Power Automate. Whenever we need to substract dates, we usually think of the functions – diffInDays, diffInMonths etc.

While the method described here works too, there is a better way to achieve this. You can check it out here.

Not quite straight forward with Power Automate but you can accomplish the requirement without much complexity here. And the function that come to our rescue is the ticks function.

Let’s see how we can achieve our goal here.

For this demo, I have created a very simple flow with a manual trigger. And I would like to calculate the difference in days between Jan-01-2020 and Mar-31-2021

I use the Compose action to take the ticks value of 1st January 2020

substract  two dates in Power Automate

Similarly I use the the ticks function to get the ticks value of Mar-31-2021

substract  two dates in Power Automate

In the next step, I use a variable to hold the difference in ticks value.

substract  two dates in Power Automate

And finally the one we were looking for, the difference in days.

substract  two dates in Power Automate
1 day = 864000000000 ticks

Same way you can use the below functions.

Diff In Months - div(variables('DiffInTicks'),mul(864000000000, 12))
Diff In hours - div(mul(variables('DiffInTicks'), 24),864000000000)

Similar you can calculate the other values as required.

Hope this helped!

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

1 thought on “How to substract two datetime objects in Power Automate”

Comments are closed.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading