Matthew Pans
Matthew Pans

Reputation: 783

Xamarin forms: How to make time picker to not allow past time being picked

In my project, I'm using TimePicker for choosing time. Using that I"m creating some events on my app.

My problem is when I open a TimePicker I need to disable the past time.

For Example, If the current time is 10:15 AM, I need to disable all the past time from 12 AM to 10:14 AM. Is there any property available for this kind of feature?

For DatePicker we have a property called MinimumDate. But I don't see anything similar for the time picker.

Upvotes: 1

Views: 674

Answers (1)

Sreejith Sree
Sreejith Sree

Reputation: 3681

When you call the save function for the event, (after choosing time) add validation for the time like below:

if ((DateTime.Now.TimeOfDay < timePicker.Time)
{
     Debug.WriteLine("choosed time is future time");
}
else
{
    Debug.WriteLine("choosed time is past time");
}

If the code is hitting the if block, the time picker has a future time and if it is on the else block the chosen time is from the past.

Upvotes: 2

Related Questions