Finding differences in dates can be a useful skill in different scenarios where one might need to know the years, months, or days between two different dates. Thankfully Power Automate has a simple solution using the dateDifference() expression.
In this blog, we will go through how to create a simple flow that will use the dateDifference() expression to check two different dates using Power Automate.
Here is the syntax for the dateDifference() expression:
dateDifference('<startDate>', '<endDate>')
Step 1: Create A New instant cloud flow in your M365 Environment.

Step 2: Add a compose action card with the following details.
dateDifference('2014-09-08T10:30:00', '2024-07-30T14:45:30')

Step 3: Save & Test the flow. Your results should be as shown below.

The results are in a Days.Hours:Minutes:Seconds format
Now what if you wanted to Extract certain values from your result such as days, hours, minutes, or seconds. This can be done by using the split () function.
To fully understand the different parts of the expression we will use to extract the days follow the below explanation.
- The
split()
function splits the output of dateDifference() at the period (‘.’) into an array with two elements: days and the rest (hours:minutes:seconds). - The
[0]
indexer retrieves the first element of the array, which represents the number of days. - The
int()
function converts the days from a string to an integer. - Replace the date time values with your dates/time
Extract Days
To extract the days value from the result use the expression shown below in a compose action card and your result will be as shown in the compose action card.
int(split(split(dateDifference('2014-09-08T10:30:00', '2024-07-30T14:45:30'), '.')[0], ':')[0])
