theburningfire
theburningfire

Reputation: 511

How to initally display two different dates in two different date time picker in winform?

I have a winform that contains two datetime picker one name start time and second is end time, now when i run my winform the value displayed in both the date time picker are same i.e current date time. But i wanted it to be like that my end time datetime picker shows current date time and start time datetime picker shows 24 hrs previous time.

Tell me how to do that, i have set the format property of datetime picker to custom.

Upvotes: 0

Views: 114

Answers (2)

user4182984
user4182984

Reputation: 222

You can change the selected date by setting the Value property. There is an example in the official docs.

Upvotes: 1

TheGeneral
TheGeneral

Reputation: 81493

Just set the appropriate fields on form load, or in the constructor after initalization

dateTimePicker1.Value = DateTime.Now;
dateTimePicker2.Value =  DateTime.Now.Days(-1);

DateTimePicker.Value Property

Gets or sets the date/time value assigned to the control.

Upvotes: 3

Related Questions