cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Setayesh2
Helper II
Helper II

calculate difer date and time

Hi,

would you advise how to calculate different dates and times in the power app?

Setayesh2_1-1645435956127.png

 

TotalTime is a text column in SharePoint

 

 

Thanks in advance

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi @Setayesh2 

The data in your formula is the value obtained from the data source. If you want to obtain the value from the control, should refer to the value of the control.

Please try following formula:

With(
{
days: RoundDown(DateDiff(DateValue1.SelectedDate + Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
        ),
        DateValue2.SelectedDate + Time(
            Value(HourValue2.Selected.Value),
            Value(HourValue2.Selected.Value),
            0
        ), Hours) / 24, 0),
hours: Mod(RoundDown(DateDiff(DateValue1.SelectedDate + Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
        ),
        DateValue2.SelectedDate + Time(
            Value(HourValue2.Selected.Value),
            Value(HourValue2.Selected.Value),
            0
        ), Minutes) / 60, 0), 24),
minutes: Mod(DateDiff(DateValue1.SelectedDate + Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
        ),
        DateValue2.SelectedDate + Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
        ), Minutes), 60)
},
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

vLilyWmsft_0-1645601329070.png

Hope the content above may help you.

Best Regards

If my reply helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @Setayesh2 

If you want to set End Date should be greater than Start Date you can refer to below link to see if it helps.

https://www.c-sharpcorner.com/article/power-apps-validation-end-date-and-time-should-be-greater-than...

 

Hope the content above may help you.

Best Regards

If my reply helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
Setayesh2
Helper II
Helper II

I tried this function but it works for saved data. I need to calculate them at the time of change.

 

With(
{
days: RoundDown(DateDiff(ThisItem.Start, ThisItem.End, Hours) / 24, 0),
hours: Mod(RoundDown(DateDiff(ThisItem.Start, ThisItem.End, Minutes) / 60, 0), 24),
minutes: Mod(DateDiff(ThisItem.Start, ThisItem.End, Minutes), 60)
},
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

Hi @Setayesh2 

The data in your formula is the value obtained from the data source. If you want to obtain the value from the control, should refer to the value of the control.

Please try following formula:

With(
{
days: RoundDown(DateDiff(DateValue1.SelectedDate + Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
        ),
        DateValue2.SelectedDate + Time(
            Value(HourValue2.Selected.Value),
            Value(HourValue2.Selected.Value),
            0
        ), Hours) / 24, 0),
hours: Mod(RoundDown(DateDiff(DateValue1.SelectedDate + Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
        ),
        DateValue2.SelectedDate + Time(
            Value(HourValue2.Selected.Value),
            Value(HourValue2.Selected.Value),
            0
        ), Minutes) / 60, 0), 24),
minutes: Mod(DateDiff(DateValue1.SelectedDate + Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
        ),
        DateValue2.SelectedDate + Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
        ), Minutes), 60)
},
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

vLilyWmsft_0-1645601329070.png

Hope the content above may help you.

Best Regards

If my reply helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-LilyW-msft  thanks a lot. Would you also advise how I can control End date, to not set less than start date?

Hi @Setayesh2 

If you want to set End Date should be greater than Start Date you can refer to below link to see if it helps.

https://www.c-sharpcorner.com/article/power-apps-validation-end-date-and-time-should-be-greater-than...

 

Hope the content above may help you.

Best Regards

If my reply helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,972)