Compare Nullable DateTime variable for default value
c#, datetime, nullable
Solution
You can create a const:
static readonly DateTime DefaultDateTime = new DateTime(1900, 1, 1, 0, 0, 0);
and then compare this way:
DateTime? myVariable = returnedFromDb == DefaultDateTime ? default(DateTime?) : returnedFromDb;
Problem
In my C# code, I have a `DateTime?` variable. While getting the values from database it can be `null` or can have some date/time value. On the front end side I don't want to get the default value (01-01-1900 12:00:00 am). Whats the best way to compare my date variable for this default date?