web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Issue with data calcul...
Power Apps
Suggested Answer

Issue with data calculations

(1) ShareShare
ReportReport
Posted on by 33
I'm trying to calculate a persons age based on 2 different date selectors.  This is what I have
 
DateDiff(
    'DatePicker1'.SelectedDate,
    DPR2.SelectedDate,
    TimeUnit.Years
) - If(
    DPReturnC1.SelectedDate < DateAdd(
        'DatePicker1'.SelectedDate,
        DateDiff(
            'DatePicker1'.SelectedDate,
            DPR2.SelectedDate,
            TimeUnit.Years
        ),
        TimeUnit.Years
    ),
    1,
    0
)
 
and for the most part it works fine !  However if I have a date for DatePicker1  well in the past for example January 10th 1960 and DPR2 is sometime this year it doesn't calculate correctly. It's giving an age of 9 !  Instead of 65 :)
 
Any ideas
I have the same question (0)
  • Suggested answer
    SaiRT14 Profile Picture
    1,990 Super User 2025 Season 1 on at
    Hi 
     
    Pls try the following:
    DateDiff(
        DatePicker1.SelectedDate,
        DPR2.SelectedDate,
        TimeUnit.Years
    ) - If(
        DateValue(
            Text(
                DatePicker1.SelectedDate,
                "MM/dd"
            ) & "/" & Year(DPR2.SelectedDate)
        ) > DPR2.SelectedDate,
        1,
        0
    )
     
    thanks
     
     
  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at
    Hi @DBNL
    You can try this, however some testing here reveals DateDiff (in fact any Date function) does not like dates before 1/1/1970
    DateDiff(
       DatePicker1.SelectedDate,
       DPR2.SelectedDate,
       TimeUnit.Years
    ) - 
    If(
       Month(DatePicker1.SelectedDate) > Month(DPR2.SelectedDate) || 
       (
         Month(DatePicker1.SelectedDate) = Month(DPR2.SelectedDate)  && 
          Day(DatePicker1.SelectedDate) > Day(DPR2.SelectedDate)
       ),
       1
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • WarrenBelz Profile Picture
    154,447 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
wolenberg_ Profile Picture

wolenberg_ 119 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 107 Most Valuable Professional

#3
Haque Profile Picture

Haque 103

Last 30 days Overall leaderboard