Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable some dates on a DateTimePicker control?

I was wondering is it possible to disable selected dates in a DateTimePicker, so that user cannot select them. i know its possible in web forms but in windows forms im unable to do this.how can i achieve this.

like image 495
Aneef Avatar asked Mar 02 '10 08:03

Aneef


People also ask

How do I restrict date in date picker?

You can restrict the users from selecting a date within the particular range by specifying MinDate and MaxDate properties. The default value of MinDate property is 1/1/1920 and MaxDate property is 12/31/2120 . Dates that appears outside the minimum and maximum date range will be disabled (blackout).

How do you turn off future date in date range picker?

daterangepicker({ autoUpdateInput: false, locale: { cancelLabel: 'Clear', format: 'DD-MM-YY' } });

How do I disable Saturday and Sunday on Datepicker?

To disable the weekends in Bootstrap Datepicker you need to set the daysOfWeekDisabled property value to [0, 6]. Then all the Weekends will be disabled in the datepicker control.


1 Answers

The ease with which you can do this will depend on the dates you want to restrict. For instance, if you all you want to do is specify a range of valid dates to pick, then you can use the MinDate and MaxDate properties to set the bounds. If however, you want to cherry pick certain days within a range (for instance, no weekends), there is no built in method for doing this.

You could either find a third party control with this functionality, or you could try to hack it a bit by adding an event handler to the ValueChanged event, and forcing the current date time to the last value (which you'd have to cache) if they user picked something that was illegal according to your business logic... but this is a less than ideal way to do it.

like image 51
Nick Avatar answered Oct 18 '22 13:10

Nick