Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combining DatePicker and TimePicker

Tags:

c#

winforms

typically when I have a timepicker and a datePicker on a winform I combine the two into one date object by using the new DateTime (y,m,d,h,mi,s) constructor. this seems kind of long winded, and I was wondering what approach others are using if faced with this situation.

DateTime date = 
new DateTime(DatePicker.Value.Year, DatePicker.Value.Month,  DatePicker.Value.Day, 
             TimePicker.Value.Hour, TimePicker.Value.Minute, TimePicker.Value.Second); 

enter image description here

looks like it was just a simple.

DateTime date  = DatePicker.Value.Date.Add(TimePicker.Value.TimeOfDay);

I didn't realize

like image 942
Brad Avatar asked Feb 25 '23 03:02

Brad


2 Answers

hope you have used DateTimePicker for selecting Date and Time. in this case you can combine date and time like

DateTime date = DatePicker.Value.Date + TimePicker.Value.TimeOfDay;
like image 63
Binil Avatar answered Mar 11 '23 22:03

Binil


Have you tried DateTimePicker ?

like image 26
Lucas B Avatar answered Mar 11 '23 20:03

Lucas B