cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

how to get difference between two dates in flow

i have date columns in sharepoint list 

i want to set difference between two dates in  variable

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: how to get difference between two dates in flow

Hi @Tejaswini1234 ,

Could you please share a bit more about your scenario?

Do you want to calculate the difference between two date column values using Microsoft Flow?

 

Currently, within Microsoft Flow, there is no direct way to calculate the difference between two different date values.

 

As an alternative solution, I think the ticks() function within Microsoft Flow WDL expression could achieve your needs. I have made a test on my side, please take a try with the following workaround:1.JPG

 

2.JPG

Add a "Initialize variable" action to initialize a variable to store the date difference.

Within the "StartTimeTickValue" action ("Compose" action), Inputs field set to following:

ticks(triggerBody()?['StartTime'])

Within the "EndTimeTickValue" action ("Compose" action), Inputs field set to following:

ticks(triggerBody()?['EndTime'])

Within the "DifferenceAsMinutes" action ("Compose" action), Inputs field set to following:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000),60)

Within the "Set variable" action, Value field set to Output dynamic content of the above "DifferenceAsMinutes" action.

The "StartTime" and "EndTime" are both date time type columns in my SP list. The passed "StartTime" value and "EndTime" value as below:3.JPG

The flow executes successfully as below:4.JPG

If you want to calculate the Hours difference between two different date values, please consider go to the "DifferenceAsMinutes" action, then modify the Inputs field value to following:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000), 3600)

If you want to calculate the Hours difference between two different date values, please modify above formula as below:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000), 86400)

 

More details about using expression in flow actions, please check the following blog:

https://flow.microsoft.com/en-us/blog/use-expressions-in-actions/

 

In addition, you could also consider achieve your needs using the DateDiff() function within PowerApps. More details about the DateDiff() function in PowerApps, please check the following article:

DateDiff function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Highlighted
Community Support
Community Support

Re: how to get difference between two dates in flow

Hi @Tejaswini1234 ,

Could you please share a bit more about your scenario?

Do you want to calculate the difference between two date column values using Microsoft Flow?

 

Currently, within Microsoft Flow, there is no direct way to calculate the difference between two different date values.

 

As an alternative solution, I think the ticks() function within Microsoft Flow WDL expression could achieve your needs. I have made a test on my side, please take a try with the following workaround:1.JPG

 

2.JPG

Add a "Initialize variable" action to initialize a variable to store the date difference.

Within the "StartTimeTickValue" action ("Compose" action), Inputs field set to following:

ticks(triggerBody()?['StartTime'])

Within the "EndTimeTickValue" action ("Compose" action), Inputs field set to following:

ticks(triggerBody()?['EndTime'])

Within the "DifferenceAsMinutes" action ("Compose" action), Inputs field set to following:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000),60)

Within the "Set variable" action, Value field set to Output dynamic content of the above "DifferenceAsMinutes" action.

The "StartTime" and "EndTime" are both date time type columns in my SP list. The passed "StartTime" value and "EndTime" value as below:3.JPG

The flow executes successfully as below:4.JPG

If you want to calculate the Hours difference between two different date values, please consider go to the "DifferenceAsMinutes" action, then modify the Inputs field value to following:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000), 3600)

If you want to calculate the Hours difference between two different date values, please modify above formula as below:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000), 86400)

 

More details about using expression in flow actions, please check the following blog:

https://flow.microsoft.com/en-us/blog/use-expressions-in-actions/

 

In addition, you could also consider achieve your needs using the DateDiff() function within PowerApps. More details about the DateDiff() function in PowerApps, please check the following article:

DateDiff function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
New Member

Re: how to get difference between two dates in flow

Thanks @v-xida-msft for this solution, it worked just fine!

 

I think there is a small mistake in your post. The following formula calculates the difference in days (not in hours) if I'm not mistaken:

div(div(mul(sub(outputs('EndTimeTickValue'),outputs('StartTimeTickValue')),100),1000000000), 86400)

Best regards

Sebastian

Highlighted
Advocate I
Advocate I

Re: how to get difference between two dates in flow

In spite a bit annoyed and elaborated, and surprised that Power Automate doesn't have direct functions to perform simple Date differences, this workaround worked well for me.

 

 

Thanks,

Abhijith

Helpful resources

Announcements
Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (12,150)