A date object always contains both a date component and a time component. When you fetch a DateTime's value via a format you are actually getting a string. The underlying DateTime object - it's value - is not changed at all.
DateTime date1 = new DateTime(2012, 12, 25, 3, 30, 0);
DateTime date2 = new DateTime(2012, 12, 25, 8, 15, 0);
// the dates are the same, the times are different
if (date1.ToShortDateString() == date2.ToShortDateString()) {
Console.WriteLine ("Date1 equals Date2"); // you should get this
} else {
Console.WriteLine ("Date1 DOES NOT equal Date2");
}
if (date1 == date2) {
Console.WriteLine ("Date1 equals Date2");
} else {
Console.WriteLine ("Date1 DOES NOT equal Date2"); // you should get this
}
if (date1.Date == date2.Date) {
Console.WriteLine ("Date1 equals Date2"); // you should get this
} else {
Console.WriteLine ("Date1 DOES NOT equal Date2");
}
Convert.ToDateTime()work for you. – svick Dec 19 '12 at 13:23