How to Calculate Age in Power Apps? [Years, Months, Days]

Many apps require knowing a person’s age, whether it’s for managing employee records, event registrations, or customer details. Power Apps makes it easy to calculate age based on a birthday.

In this tutorial, I will discuss how to calculate age in Power Apps, including years, months, and days, with various formulas.

So let’s get started!

Calculate Age in Power Apps

In this example, we’ll use a date picker control. The user can select a date, such as their birthday, and the app will calculate their age and display it on a label.

The age is calculated automatically by comparing today’s date with the birthday they select.

To do this, I’ll use two different formulas below:

Code – 1:

Select the Label control and apply the following formula to its Text property:

"Age: " & DateDiff(
    dtSelectDate.SelectedDate,
    Today(),
    TimeUnit.Years
)

OR

"Age: " & DateDiff(
    dtSelectDate.SelectedDate,
    Now(),
    TimeUnit.Years
)

Where,

  1. “Age: ” = This is the string that I want to display in the label control
  2. dtSelectDate = Name of the Date Picker control

Also, you can refer to the screenshot below.

PowerApps calculate age

Code – 2:

In the same way, select the Label control and set the below code on its Text property as:

"Age: " & If(
    DateDiff(
        Today(),
        Date(
            Year(Now()),
            Month(dtSelectDate),
            Day(dtSelectDate)
        )
    ) <= 0,
    DateDiff(
        dtSelectDate,
        Today(),
        Years
    ),
    DateDiff(
        dtSelectDate,
        Today(),
        Years
    ) - 1
)

Where,

dtSelectDate = Specify the date picker control name

Power Apps calculate age

Finally, save and preview the app. Select any date from the date picker, and you can see the age on the label.

Power Apps Calculate Age Based On Specified Time Unit (Years, Months, Days)

Next, we will discuss how to calculate the age difference based on the specified time unit, either in years, months, or days.

Here, in the image below, I have taken a Modern date picker and a label control. When the user selects a specific date from the date picker, the result will display in years, months, and days.

Calculate Age in Power Apps

To achieve this, select the Label and set its Text property as:

If(
    DateDiff(
        DatePickerCanvas1.SelectedDate,
        Today(),
        TimeUnit.Days
    ) < 365,
    Concatenate(
        "0 years ",
        Int(
            DateDiff(
                DatePickerCanvas1.SelectedDate,
                Today(),
                TimeUnit.Days
            ) / 30
        ),
        " Months ",
        Int(
            Mod(
                DateDiff(
                    DatePickerCanvas1.SelectedDate,
                    Today(),
                    TimeUnit.Days
                ),
                30
            )
        ),
        " days"
    ),
    Concatenate(
        DateDiff(
            DatePickerCanvas1.SelectedDate,
            Today(),
            TimeUnit.Years
        ),
        " Years"
    )
)

Where,

  • DateDiff(date1, date2, timeunit): This function calculates the difference between two dates based on the specified time unit (Years, Months, Days, etc.).
  • DatePickerCanvas1: Modern Date picker control name.
  • Today(): Returns the current date.
  • Years, Months, Days: Specify the time unit for the difference.
  • Int(): Converts a decimal number to an integer (whole number).
  • Mod(): Returns the remainder of a division.
  • Concatenate(): Joins text strings together.
Power Apps Calculate Age Based On Specified Time Unit

Save, publish, and preview the app. Select any specific date from the modern date picker control, and the age will be calculated and displayed on the label.

Calculate Age in Power Apps With Years, Months, Days

To accurately calculate age in Power Apps with years, months, and days, we’ll need to compare the selected birthdate with today’s date carefully.

Calculate Age in Power Apps With Years, Months, Days

Let’s copy the code below and paste it into the Label’s Text property: (replace your Date picker control name)

With(
    {
        birth: DatePickerCanvas1.SelectedDate,
        today: Today(),
        totalYears: DateDiff(
            DatePickerCanvas1.SelectedDate,
            Today(),
            TimeUnit.Years
        ),
        birthdayThisYear: DateAdd(
            DateValue(
                Text(
                    Today(),
                    "[$-en-US]yyyy"
                ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
            ),
            0
        ),
        adjustYear: If(
            Today() < DateAdd(
                DateValue(
                    Text(
                        Today(),
                        "[$-en-US]yyyy"
                    ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                ),
                0
            ),
            -1,
            0
        ),
        years: DateDiff(
            DatePickerCanvas1.SelectedDate,
            Today(),
            TimeUnit.Years
        ) + If(
            Today() < DateAdd(
                DateValue(
                    Text(
                        Today(),
                        "[$-en-US]yyyy"
                    ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                ),
                0
            ),
            -1,
            0
        ),
        yearAdjustedDate: DateAdd(
            DatePickerCanvas1.SelectedDate,
            DateDiff(
                DatePickerCanvas1.SelectedDate,
                Today(),
                TimeUnit.Years
            ) + If(
                Today() < DateAdd(
                    DateValue(
                        Text(
                            Today(),
                            "[$-en-US]yyyy"
                        ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                    ),
                    0
                ),
                -1,
                0
            ),
            TimeUnit.Years
        ),
        months: DateDiff(
            DateAdd(
                DatePickerCanvas1.SelectedDate,
                DateDiff(
                    DatePickerCanvas1.SelectedDate,
                    Today(),
                    TimeUnit.Years
                ) + If(
                    Today() < DateAdd(
                        DateValue(
                            Text(
                                Today(),
                                "[$-en-US]yyyy"
                            ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                        ),
                        0
                    ),
                    -1,
                    0
                ),
                TimeUnit.Years
            ),
            Today(),
            TimeUnit.Months
        ),
        monthAdjustedDate: DateAdd(
            DateAdd(
                DatePickerCanvas1.SelectedDate,
                DateDiff(
                    DatePickerCanvas1.SelectedDate,
                    Today(),
                    TimeUnit.Years
                ) + If(
                    Today() < DateAdd(
                        DateValue(
                            Text(
                                Today(),
                                "[$-en-US]yyyy"
                            ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                        ),
                        0
                    ),
                    -1,
                    0
                ),
                TimeUnit.Years
            ),
            DateDiff(
                DateAdd(
                    DatePickerCanvas1.SelectedDate,
                    DateDiff(
                        DatePickerCanvas1.SelectedDate,
                        Today(),
                        TimeUnit.Years
                    ) + If(
                        Today() < DateAdd(
                            DateValue(
                                Text(
                                    Today(),
                                    "[$-en-US]yyyy"
                                ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                            ),
                            0
                        ),
                        -1,
                        0
                    ),
                    TimeUnit.Years
                ),
                Today(),
                TimeUnit.Months
            ),
            TimeUnit.Months
        ),
        days: DateDiff(
            DateAdd(
                DateAdd(
                    DatePickerCanvas1.SelectedDate,
                    DateDiff(
                        DatePickerCanvas1.SelectedDate,
                        Today(),
                        TimeUnit.Years
                    ) + If(
                        Today() < DateAdd(
                            DateValue(
                                Text(
                                    Today(),
                                    "[$-en-US]yyyy"
                                ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                            ),
                            0
                        ),
                        -1,
                        0
                    ),
                    TimeUnit.Years
                ),
                DateDiff(
                    DateAdd(
                        DatePickerCanvas1.SelectedDate,
                        DateDiff(
                            DatePickerCanvas1.SelectedDate,
                            Today(),
                            TimeUnit.Years
                        ) + If(
                            Today() < DateAdd(
                                DateValue(
                                    Text(
                                        Today(),
                                        "[$-en-US]yyyy"
                                    ) & "-" & Text(Month(DatePickerCanvas1.SelectedDate)) & "-" & Text(Day(DatePickerCanvas1.SelectedDate))
                                ),
                                0
                            ),
                            -1,
                            0
                        ),
                        TimeUnit.Years
                    ),
                    Today(),
                    TimeUnit.Months
                ),
                TimeUnit.Months
            ),
            Today(),
            TimeUnit.Days
        )
    },
    Concatenate(
        years,
        " years, ",
        months,
        " months, ",
        days,
        " days"
    )
)

Refer to the image below:

Power Apps Calculate Age

I hope this guide helped you understand how to calculate age in Power Apps. Also, we covered how to work with Power Apps to calculate age based on specified time units, including Years, Months, and Days, with various examples.

Additionally, you may like some more Power Apps articles:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App