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 / Logic to display warni...
Power Apps
Answered

Logic to display warning if end datetime is before start datetime

(0) ShareShare
ReportReport
Posted on by 87

I'm trying to build custom date and time selectors. I want a warning to display when the end time is before the start time. 

 

elbent_0-1699896367033.png

 

The text boxes in the top left are variables that are set when the selectors are changed. As you can see, the end time is before the start time. In the warning box I have the following in the visible property:

 

If(DateDiff(varStartTime, varEndTime)<0, true, false)

 

I have also tried:

If(DateDiff(DateTimeValue(varStartTime), DateTimeValue(varEndTime))<0, true, false)

 

This is the code that is in the OnSelect and OnChange of the start time selectors:

 

Set(varStartTime, DateTime( Year(DateStart.SelectedDate), Month(DateStart.SelectedDate), Day(DateStart.SelectedDate), If(StartTimeAMPM.Selected.Value = "PM" && Value(StartTimeHour.SelectedText.Value) <> 12, Value(StartTimeHour.SelectedText.Value) + 12, If(StartTimeAMPM.Selected.Value = "AM" && Value(StartTimeHour.SelectedText.Value) = 12, 0, Value(StartTimeHour.SelectedText.Value) ) ), Value(StartTimeMinute.SelectedText.Value), 0 ) );

 

And this is in the end time selectors:

 

Set(varEndTime, DateTime( Year(DateEnd.SelectedDate), Month(DateEnd.SelectedDate), Day(DateEnd.SelectedDate), If(EndTimeAMPM.Selected.Value = "PM" && Value(EndTimeHour.SelectedText.Value) <> 12, Value(EndTimeHour.SelectedText.Value) + 12, If(EndTimeAMPM.Selected.Value = "AM" && Value(EndTimeHour.SelectedText.Value) = 12, 0, Value(EndTimeHour.SelectedText.Value) ) ), Value(EndTimeMinute.SelectedText.Value), 0 ) );

 

 

Why is the warning not showing when the start time is after the end time? Thanks.

Categories:
I have the same question (0)
  • Verified answer
    MiDer Profile Picture
    139 on at

    @elbent 
    The DateDiff expression would give the the difference in return with the unit defined by the 3rd parameter.
    Regardless the position of its first two parameters, thus you will not get a negative value in return.

    You could try the following for your warning box visibility instead:

    If(DateTimeValue(varEndTime) <= DateTimeValue(varStartTime),true,false)

     

  • elbent Profile Picture
    87 on at

    Thank you! I don't know why I didn't just try a simple comparison.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 88

#2
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 45

Last 30 days Overall leaderboard