
Announcements
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.
Hi@
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"
)
)
)