Need help with age calculation

Power Apps Help

Hi everyone,

I'm working on a PowerApps formula to calculate age from a date of birth and display it as years, months, and days. It mostly works fine, but I'm encountering an issue where the calculation returns negative values for individuals under one year old.

Here's the formula I'm using:

"Age: " & Concatenate(
    DateDiff(DataCardValue70.SelectedDate, Today(), TimeUnit.Years)-1, " years, ",
    Int(Mod(DateDiff(DataCardValue70.SelectedDate, Today(), TimeUnit.Months), 12))-1, " months, ",
    Int(Mod(DateDiff(DataCardValue70.SelectedDate, Today(), TimeUnit.Days),30.1)), " days"
)

I suspect the issue might be related to subtracting 1 here:

  • DateDiff(DataCardValue70.SelectedDate, Today(), TimeUnit.Years)-1
  • Int(Mod(DateDiff(DataCardValue70.SelectedDate, Today(), TimeUnit.Months), 12))-1

If anyone has encountered a similar issue or has a suggestion for correcting this, I would appreciate your help. I'm aiming for a solution that accurately accounts for babies under one year, showing correct months and days without negative numbers.

Thanks in advance for your assistance!

Posted Apr 9, 2025, 5:50 PM UTC

36

Comments aren't archived yet

This post had 6 comments on Reddit. Comments for this period haven't been loaded into the archive yet.