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 Apps
Unanswered

DATEDIF

(0) ShareShare
ReportReport
Posted on by 162

Good Day!

how to convert this from Excel Formula to PowerApps
=Datediff(Start_Date,End_Date + 1,"y")

=Datediff(Start_Date,End_Date + 1,"ym")

=Datediff(Start_Date,End_Date + 1,"md")

How can I get the exact result ?


thanks.

Categories:
I have the same question (0)
  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    on at

    Hi@DHAGZ,

    Do you want to calculate the year, month, day difference?

    Could you please tell me more about your scenario, do you format your date column as a Date type?

    Generally, we could calculate the date difference and display the result in a Label as follows:

    This will calculate the Year difference:

     

    Text(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Years))

     

    Note: You could replace the DatePicker1.SelectedDare as your StartDate.

    Here's another assumption that if you want to display the date difference in year, month and day.

    I found that you have created a similar case before, @RusselThomas  has provided excellent answers.

    Is there anything different you want to clarify this time?

    If you do want to display date separately in years, months and days, please try the following formula.

    1). Datediff(Start_Date,End_Date + 1,"y")

    With(
     {
     totalDays: DateDiff(
     DatePicker1.SelectedDate,
     DatePicker2.SelectedDate,
     Days
     ) + 1
     },
     With(
     {
     totalYears: RoundDown(
     totalDays / 365,
     0
     ),
     remainingDaysFromYearsRollUp: Mod(
     totalDays,
     365
     )
     },
     totalYears & "years"
     )
    )

    2). Datediff(Start_Date,End_Date + 1,"ym")

    With(
     {
     totalDays: DateDiff(
     DatePicker1.SelectedDate,
     DatePicker2.SelectedDate,
     Days
     ) + 1
     },
     With(
     {
     totalYears: RoundDown(
     totalDays / 365,
     0
     ),
     remainingDaysFromYearsRollUp: Mod(
     totalDays,
     365
     )
     },
     With(
     {
     MonthsInRemainingDays: RoundDown(
     remainingDaysFromYearsRollUp / 30,
     0
     ),
     remainingDaysFromMonthsRollUp: Mod(
     remainingDaysFromYearsRollUp,
     30
     )
     },
     totalYears & " years / " & MonthsInRemainingDays & " months " 
     )
     )
    )

    3). Datediff(Start_Date,End_Date + 1,"md")

    With(
     {
     totalDays: DateDiff(
     DatePicker1.SelectedDate,
     DatePicker2.SelectedDate,
     Days
     ) + 1
     },
     With(
     {
     totalMonths: RoundDown(
     totalDays / 30,
     0
     ),
     remainingDaysFromMonthsRollUp: Mod(
     totalDays,
     30
     )
     },
     With(
     {
     MonthsInRemainingDays: RoundDown(
     remainingDaysFromMonthsRollUp / 30,
     0
     ),
     remainingDaysFromMonthsRollUp: Mod(
     remainingDaysFromMonthsRollUp,
     30
     )
     },
     totalMonths & " months / " & remainingDaysFromMonthsRollUp & " days"
     )
     )
    )

    Regards,

    Qi

     

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 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard