Skip to main content

Notifications

Community site session details

Community site session details

Session Id : m0cCPwzN39AVSdM7pPV9Tj
Power Apps - Building Power Apps
Answered

Calculate Age in Power Apps

Like (1) ShareShare
ReportReport
Posted on 9 Feb 2021 13:22:30 by 817

Hi All,

 

It's being quite some time since my last question here and I'm seeking all professional's assistance here.

 

I'm building a Medical App that requires the Patient's age.

What is required from the Patient to enter is just his Sex and Date of Birth, the age will be calculated automatically using Todays Data and the Birthday Data input from the Calendar 

 

This is how the screen looks like:

Radoslavov_0-1612876640423.png

The Age number is actually the main information required for the app, so this file will be hidden from the user anyway.

Any suggestions on how to calculate the Age of a Patient?

I've tried this: DateDiff(Today(),userbirthdate.SelectedDate)

but I got the difference in days

Radoslavov_1-1612876805899.png

Radoslavov_2-1612876925851.png

 

 

 

  • fatima12345 Profile Picture
    2 on 05 Apr 2023 at 08:53:53
    Re: Calculate Age in Power Apps
  • Epzone Profile Picture
    3 on 13 Jan 2022 at 19:38:28
    Re: Calculate Age in Power Apps

    DateDiff(DateTimeValue(SelectedDate),Now(),Years)

  • PapithaSekar1 Profile Picture
    100 on 27 Aug 2021 at 10:06:22
    Re: Calculate Age in Power Apps

    If(DateDiff(Today(), Date(Year(Now()), Month(birth), Day(birth))) <= 0, DateDiff(birth, Today(), Years), DateDiff(birth, Today(), Years) - 1)

    this formula is working

  • Verified answer
    MartinVasek Profile Picture
    30 on 11 Jun 2021 at 11:34:47
    Re: Calculate Age in Power Apps

    This solution looks incorrect!

     

    It returns difference between current year and year of birth but NOT age.

    For example if today is 3rd of February 2022 and someone was born on 1st of January 2000, it will return the same result as for someone born on 3rd of March 2000. Ages are obviously different (22 and 21) but for both it returns 22.

     

    For return of age I recommend to use this:

    If(DateDiff(Today(), Date(Year(Now()), Month(birth), Day(birth))) <= 0, DateDiff(birth, Today(), Years), DateDiff(birth, Today(), Years) - 1)

     

    What it does:

    It checks if desired date's day and month are lower or equal to today's day and month and if so it makes difference between years. Otherwise it makes difference between this year and desired date year and deducts 1 (because this person didn't have birthday this year yet). 

  • Radoslavov Profile Picture
    817 on 09 Feb 2021 at 21:10:06
    Re: Calculate Age in Power Apps

    This is working,I just change the formula slightly to remove the age rounding as 29 years and 9 months even if it's close to 30, the medical records think otherwise when it comes to accuracy.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on 09 Feb 2021 at 14:36:49
    Re: Calculate Age in Power Apps

    It’s not as simple as it looks because age is typically rounded down.  I did it for cds here https://powerusers.microsoft.com/t5/Microsoft-Dataverse/Calculating-age-in-CDS-entity/td-p/495528 

  • Verified answer
    eka24 Profile Picture
    20,921 on 09 Feb 2021 at 14:19:13
    Re: Calculate Age in Power Apps

    Consider this:

    DateDiff(StartDatePicker.userbirthdate,Today(),Years)

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,670 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard