When I compare a DateTime variable with SqlDateTime.MinValue:
if (StartDate > SqlDateTime.MinValue)
{
// some code
}
I get the following runtime exception if StartDate is < SqlDateTime.MinValue:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
This can be easy solved with a small change:
if (StartDate > SqlDateTime.MinValue.Value)
{
// some code
}
I understand that in the first code snippet I'm comparing apples to oranges. What I don't understand is the exception message. It seems like I'm assigning a DateTime value to a SqlDateTime variable.
What am I missing?