More on handling SQL null dates
Null SQL date values have been yankin' my nose hairs out of place lately, I think primarily because I'm using business objects more extensively which requires more value handling. I'm going to say that the following is an Insider's TIP for handling null dates until someone tells me I'm full of crap, which inevitably seems to happen with Insider Tips.
I want to display "N/A" if the date from my business object class property is null. '1/1/0001' continued to display as I went through
if (datein.Year == 1)..... if (datein.Year == null).... if (datein.Year.ToString() = '1/1/0001').... if (datein.Year == System.DBNull.Value)
Then I went with the following, which seems to do the trick. Seems if I compare the Year of a null value to a date that I know is less than any other date in the system that I'll achieve the desired results.
public string NAitDate(System.DateTime datein)
{
if (datein.Year < 1950)
return "N/A";
else
return datein.ToShortDateString();
}