alexander
alexander

Reputation: 45

I confuse with datatimepickers and datetimes. Need some help

Need some your help.

I have two datetimepickers on my form: dt1 and dt2.

dt1 is for picking a date.

dt2 is for picking a time.

How can I get a DateTime dt where Date component is from dt1 and time component is from dt2 ?

C#, .net 2.0

Upvotes: 2

Views: 51

Answers (1)

mellamokb
mellamokb

Reputation: 56769

You can read the Date component from the value of dt1 and the time component from the value of dt2 and combine them with the Add method, like this:

DateTime theDate = dt1.Value.Date;
TimeSpan theTime = dt2.Value.TimeOfDay;

DateTime dt = theDate.Add(theTime);

// dt now contains date from dt1 and time from dt2

Upvotes: 3

Related Questions