C# – Replace date in a DateTime with another date

c++

How do you change the day part of a DateTime structure?

I have a DateTime with the value of 3/31/2009 8:00:00 AM and would like to change it to any other date but the time should be same. I don't need a solution to add day(s), I need to replace it with any arbitrary date.

How do I achieve this?

Best Solution

day = 1
month = 4
year = 2009

Date2 = new DateTime(day,month,year,Date1.Hours,Date1.Minute,Date1.Seconds)