Reputation: 31
If I do this:
dateTimePicker1.Value = DateTime.Today;
The date gets set to today's date but the time gets set to 12:00:00 AM. I don't want the time to be changed.
Any help appreciated (I searched quite a bit for this)
Thanks
Upvotes: 0
Views: 2002
Reputation: 5325
As the according MSDN-site states, DateTime.Today is:
An object that is set to today's date, with the time component set to 00:00:00.
This means you have to "save" your time before setting the new DateTime
:
dateTimePicker1.Value = DateTime.Today.Add(dateTimePicker1.Value.TimeOfDay);
This now adds the time of your DateTimePicker
to your date with the time 12:00:00AM / 00:00:00, meaning it gets set to the time before.
Upvotes: 1