I want user to select only dates of the current month I don't know what should put in min and max date property.
Is there any property of something like ' current month '?
I want user to select only dates of the current month I don't know what should put in min and max date property.
Is there any property of something like ' current month '?
Since both MinDate
and MaxDate
property takes DateTime
, you can set them like;
DateTimePicker1.MinDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
DateTimePicker1.MaxDate = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))
.AddMonths(1).AddDays(-1);
Yes, you can use properties MinDate and MaxDate and sets minimum and maximum dates which can be selected in control.
var currentYear = DateTime.Now.Year;
var currentMonth = DateTime.Now.Month;
int firstDayInCurrentMonth = 1;
int lastDayInCurrentMonth = DateTime.DaysInMonth(currentYear, currentMonth);
dateTimePicker.MinDate = new DateTime(currentYear, currentMonth, firstDayInCurrentMonth);
dateTimePicker.MaxDate = new DateTime(currentYear, currentMonth, lastDayInCurrentMonth);