web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can I user PowerAutoma...
Power Apps
Unanswered

Can I user PowerAutomate Flow to calculate the NoOfDAys between two dates in Model Driven Apps

(0) ShareShare
ReportReport
Posted on by 1,302

Hi

 

Can I use PowerAutomate Flow to calculate the difference between two dates  in a Model Driven App ?

 

Regards

 

Nigel

Categories:
I have the same question (0)
  • the_dude Profile Picture
    361 Super User 2024 Season 1 on at

    Hi NigelP,

    Not an expert on model driven apps, but plenty of experience with flows. I'm not sure about the context of your app, thought in my understanding it has to be based on dataverse tables.

    Regardless how you wish to trigger the flow, to calculate the difference between two dates in days there's generally two ways.

     

     

    as you can see in the above screenshot, the datediff function produced '5.00:00:00' which we can easily turn into '5' by taking a substring, if you need some help with this just let me know

     

     

    1. DateDiff Function:

    How the datediff function implementation works, be mindful - datediff function requires the datetime to be formatted as 'yyyy-MM-dd'  or it won't work.  This can be easily achieved by taking your datetime value and running it through the FormatDateTime function as such  FormatDateTime(YOURDATETIME,'yyyy-MM-dd') dateDifference(outputs('compose_Today''s_date'),outputs('compose_5_days_from_now')) Where outputs('compose_Today''s_date') and outputs('compose_5_days_from_now') are simply blocks i used to create a datetime on the run, in your version it would be the 2 fields you get from dataverse.

     

     

     

    2. Taking the 'ticks' of the datetime values and calculate from there

     

    Block 1:

    ticks(outputs('compose_Today''s_date'))  

     

    Block 2:

    ticks(outputs('compose_5_days_from_now'))  

     

    Block 3 (where the magic happens): div(sub(outputs('5_days_from_now''s_ticks'),outputs('today''s_ticks')),864000000000)

     

    So what happens here? we take the tick value of the 2 dates in block 1 and 2 and then in block 3 we substract the future (furthest) date from todays (closest) date and then divide that by 864000000000 since 1 day consists of that many ticks. 

     

    Naturally you can also subtract them the other way around, but instead of 5 it would have produced -5  To circumvent this you can multiply by -1  (*-1) to turn a negative number into positive and the other way around. If the dates aren't always consistent (ie; column 1 isnt always before column 2 or other way around) you can always do a check whether the result is smaller than 0 and if so multiply it by -1.  

     

    I hope this helps. If it solves your issue please mark as solved - otherwise let me know and im happy to help!  

     

     

     

    What are ticks?  (A tick is the smallest unit of time in the .NET DateTime structure and is defined as 100 nanoseconds (or one ten-millionth of a second. In other words, one tick is equal to 0.0000001 seconds, or 100 nanoseconds. The .NET DateTime structure uses ticks to represent the number of ticks that have elapsed since January 1, 0001, at 00:00:00.000 in the Gregorian calendar (known as the "ticks epoch"). This means that each DateTime value represents a specific point in time relative to this epoch. Ticks are commonly used for high-precision time calculations and can be used to measure extremely small time intervals or durations. For simplicity sake I split this one up in 3 compose blocks, but it can all be combined into one expression as wel. again - if you need help doing this just let me know.)

  • the_dude Profile Picture
    361 Super User 2024 Season 1 on at

    having the greatest difficulty adding the screenshot and NOT ruining the layout of my reply.... so here is the screenshot

     

    the_dude_0-1690550662755.png

     

  • the_dude Profile Picture
    361 Super User 2024 Season 1 on at

    having the greatest difficulty adding the screenshot and NOT ruining the layout of my reply.... so here is the screenshot

     

    the_dude_0-1690550662755.png

     

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @NigelP 

    Hopefully @the_dude's post answers the question on how to do the calcuation in Power Automate.

    As an additional comment, do you want to display the result in your model driven app? If so, have you considered using a formula column to do this calculation?

    https://learn.microsoft.com/en-us/power-apps/maker/data-platform/formula-columns

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard