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.)