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.
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.
Thank you! I don't know why I didn't just try a simple comparison.
@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)