![](https://i0.wp.com/niteshkejriwal.com/wp-content/uploads/2014/05/win-forms-tips-tricks.png?resize=125%2C100&ssl=1)
How To Limit Dates in DateTimePicker Control in Windows Forms
Dear Friends,
Another small tip that may help in day-to-day code development. When working with DateTimePicker controls in Windows forms, we come across a situation where we need to block the control to have a minimum and maximum dates. For example, the DOB field cannot have dates greater than today and DateOfLeavingCompany field cannot have dates less than today. This post will explain a simple tip to resolve situations like this. To limit dates in a DateTimePicker control, we can set the MinDate and MaxDate properties of the control as below.
C#
dateTimePickerContorl1.MinDate = DateTime.Now; //Minimum Date is today dateTimePickerContorl1.MaxDate = DateTime.Now.AddMonth(1); //Maximum Date is 1 month from today
VB.Net
dateTimePickerContorl1.MinDate = DateTime.Now 'Minimum Date is today dateTimePickerContorl1.MaxDate = DateTime.Now.AddMonth(1) 'Maximum Date is 1 month from today
Hope this tip helps you! Keep learning and sharing!