The DateDiff function returns the difference between 2 dates in the specified unit. DateDiff function defaults to Days, but you can choose between Milliseconds, Seconds, Minutes, Hours, Days, Months, Quarters, or Years. If the second date occurs before the first DateDiff will return a negative number.

Limitations

  1. No week in the list of choices, but you can perform the calculation based on the difference in days and RoundUp or RoundDown based on the metric that suits your app.
  2. The returned difference is always an integer number. If you need more granularity, you need to perform the math by yourself.
  3. Please note that Power Apps will only calculate the difference based on the metric used. For example, if you compare date in days where the first is “today at 3 pm” and the other is “tomorrow at 10 am” it will return one as the number of days, even if it’s technically less than one day between both dates.

Recommendations:

  1. Always be aware of the order of the dates that you’re comparing. A negative time difference can be confusing to the end-user (the result of subtracting the most recent date with the other).
  2. Always use the metric that you need (except if you need more granularity). For example, don’t use DateDiffwith the default value and try to calculate the months. You may get invalid results, and there’s a convenient way for you to do it just by using Months.
  3. The dates are compared using the local timezone, so be aware of any differences in time zones in the data source to ensure correct results.

Localization

  1. Please note that formulas may have localization-based differences. For example, you should write DateDiff(Today(),Now()) with “,” separating each of the arguments, but if your localization is Portugal, you should use “;” instead

Sources:

DateAdd, DateDiff, and TimeZoneOffset functions in Power Apps

Back to the PowerApps Function Reference

Featured Image by Icons8 team on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

%d bloggers like this: