Disable dates before the current day in Datetimepicker?

Asked

Viewed 1,790 times

6

It is possible in the DateTimePicker, disable the days before the current day?

1 answer

5


You can do this by adding the dates you want to MinDate and MaxDate, obviously the minimum can be the smallest valid date and the maximum the day of yesterday. Something like this:

this.dateTimePicker1.MaxDate = DateTime.Today.AddDays(-1);
this.dateTimePicker1.MinDate = DateTimePicker.MinimumDateTime;

I put in the Github for future reference.

The question changed midway but the answer remains the same as it changes the control but the properties MinDate and MaxDate are identical.

  • Perfect bigown. I had put the monthCalendar, then fixed it for Datatimepicker, but it still worked its code. But when we click on the Datatimepicker, the date before the current day appears, disappearing only after we select a date. It may not appear when clicking on the Datatimepicker?

  • I believe that not to be creating a control of its own, at least I found nothing that indicated this.

  • Right. Even so his tip worked bigown. When selecting an earlier date than the current date, he puts the current date and the previous days disappear. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.