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

Notifications

Announcements

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,223 Super User 2025 Season 2 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,223 Super User 2025 Season 2 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,223 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard