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 / Difference in Calculat...
Power Apps
Unanswered

Difference in Calculation - Dates | PowerApps vs. Excel

(1) ShareShare
ReportReport
Posted on by 2

Hi,

 

I want to calculate year and months from two dates. Actually, I am replicating excel like functionality into PowerApps.

 

In Excel I have below formula.

 

Get Month =DATEDIF(B6,B7, "ym")

Get Year =DATEDIF(B6,B7, "y")

Below the output I am getting.

Excel.PNG

 

But when i am trying to enter the same dates and calculating them then getting the below results.

PowerApps.PNG

 

I am using the below PowerFX code.

DateDiff(
 Start.SelectedDate,
 End.SelectedDate,
 TimeUnit.Years
) & " Years " & Mod(
 DateDiff(
 Start.SelectedDate,
 End.SelectedDate,
 TimeUnit.Months
 ),
 12 
) & " Months "

 

Now sure why and where is the problem. I would be really glad to have help on this.

 

Warm Regards,

Akshay

Categories:
I have the same question (0)
  • ANB Profile Picture
    7,252 Super User 2026 Season 1 on at

    Hi @AkshayManke Try this:

    If(
     "." in Text(
     DateDiff(
     Start.SelectedDate,
     End.SelectedDate,
     TimeUnit.Months
     ) / 12
     ),
     First(
     Split(
     Text(
     DateDiff(
     Start.SelectedDate,
     End.SelectedDate,
     TimeUnit.Months
     ) / 12
     ),
     "."
     )
     ).Value & " Years " & Mod(
     DateDiff(
     Start.SelectedDate,
     End.SelectedDate,
     TimeUnit.Months
     ),
     12
     ) & " Months ",
     DateDiff(
     Start.SelectedDate,
     End.SelectedDate,
     TimeUnit.Months
     ) / 12 & " Years " & Mod(
     DateDiff(
     Start.SelectedDate,
     End.SelectedDate,
     TimeUnit.Months
     ),
     12
     ) & " Months "
    )

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

    I hope this helps.

    Please click Accept as solution 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 Thumbs up.👍

    Thanks,
    ANB


  • AkshayManke Profile Picture
    2 on at

    Hi @ANB, thanks a lot for the quick help.. Now the years are correct but still month is showing 10 which should be actually 9.. Can you please suggest what further i should modify to get the accurate result.

    3.PNG

     

    Many Thanks again!

  • ANB Profile Picture
    7,252 Super User 2026 Season 1 on at

    Hi @AkshayManke Check this if this can help you: https://powerusers.microsoft.com/t5/Building-Power-Apps/DATEDIFF-FUNCTION/td-p/751453

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

    I hope this helps.

    Please click Accept as solution 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 Thumbs up.👍

    Thanks,
    ANB


  • AkshayManke Profile Picture
    2 on at

    Hi @ANB, i tried that too but the month difference is still there. 

  • ANB Profile Picture
    7,252 Super User 2026 Season 1 on at

    @AkshayManke If you have read the complete post that i gave, in that people are looking similar kind of solution but getting 100% accuracy will be difficult. 

    There are lots of factors involved,  like all months are not equal in terms of days. 28, 29, 30 and 31.

    I want you read this from above post:

    ANB_1-1720156978117.png

    I am not telling that it is not possible but to build the 100% accuracy result, it is require to spent sometime. 

     

    Thanks,

    ANB

     

     

     

  • AkshayManke Profile Picture
    2 on at

    Thanks @ANB for sharing the information. I would like to keep this thread open to receive more suggestions.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 305 Most Valuable Professional

#2
11manish Profile Picture

11manish 212

#3
Valantis Profile Picture

Valantis 167

Last 30 days Overall leaderboard