I have two date properties and they are exactly the same as i am mapping from one object to another. If I compare them as below it returns false:
if(obj1.d1 == obj2.d1)
{
}
both of them are {01/06/2011 15:44:32}.
I cannot use DateTime.Compare as they are nullable. what would be the best way to compare nullable dates?
Check the actual ticks of those dates, they might be different. Note that DateTime records 100 ns intervals as its smallest unit. Those aren't shown when you format the DateTime.
You can compare nullable objects, including nullable dates, with the Nullable.Compare<T>() method.
if(Nullable.Compare(obj1.d1, obj2.d1) == 0)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With