I have two nullable datetime objects, I want to compare both. What is the best way to do it?
I have already tried:
DateTime.Compare(birthDate, hireDate);
This is giving an error, maybe it is expecting dates of type System.DateTime and I have Nullable datetimes.
I have also tried:
birthDate > hiredate...
But the results are not as expected…any suggestions?
To compare two
Nullable<T>objects useNullable.Compare<T>like:You can also do:
Use the Value property of the Nullable DateTime. (Remember to check if both object Has some values)
If both values are Same DateTime.Compare will return you
0Something Like