-2

I have a Datetime object that stores the date and time selected. The time defaulted to 12 AM and it is unchangeable unless you do it through code. I have another variable that actually stores the time.

How would I modify the time in the Datetime object to store the time value that I have in another field?

AlG
  • 14,697
  • 4
  • 41
  • 54
zms6445
  • 317
  • 6
  • 22
  • 1
    “I have another variable that stores the actually time” What is the type of that variable? – svick Apr 30 '13 at 16:52

1 Answers1

3

Just add the date portion of one to the time portion of the other:

DateTime date = DateTime.Now.Date;
DateTime time = DateTime.Now;

DateTime dateAndTime = date.Date + time.TimeOfDay;
Servy
  • 202,030
  • 26
  • 332
  • 449