DateTimePicker oddity

  • Thread starter Thread starter Andrew Ducker
  • Start date Start date
A

Andrew Ducker

The following lines of code causes an exception:

dateTimePicker1.MaxDate = DateTime.Today;
dateTimePicker1.MinDate = DateTime.Today;

The same two lines of code, the other way round, doesn't.

I'm setting both of them programmatically, and I need to be able to
cope with the situation where MaxDate and MinDate are the same (i.e.
only one date is possible).

It's a real pain that they can only be set one way round!

Andy D
 
Andrew said:
The following lines of code causes an exception:

dateTimePicker1.MaxDate = DateTime.Today;
dateTimePicker1.MinDate = DateTime.Today;

The same two lines of code, the other way round, doesn't.

I'm setting both of them programmatically, and I need to be able to
cope with the situation where MaxDate and MinDate are the same (i.e.
only one date is possible).

It's a real pain that they can only be set one way round!

Andy D
Does this help?

dateTimePicker1.MaxDate = new DateTime(DateTime.Now.Year,
DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59, 99);

dateTimePicker1.MaxDate = new DateTime(DateTime.Now.Year,
DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);


JB
 
Back
Top