How to check if a DateTime field is not null or empty? [duplicate]

If you declare a DateTime, then the default value is DateTime.MinValue, and hence you have to check it like this:

DateTime dat = new DateTime();

 if (dat==DateTime.MinValue)
 {
     //unassigned
 }

If the DateTime is nullable, well that’s a different story:

 DateTime? dat = null;

 if (!dat.HasValue)
 {
     //unassigned
 }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)