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

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

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