Home > DeveloperSection > Forums > How to validate if a DateTime field is not null / empty?
Andrew Watson
Andrew Watson

Total Post:39

Posted on    February-10-2015 5:29 AM

 C# C# 

 1 Reply(s)
 751  View(s)
Rate this:

I found something like:

if (!String.IsNullOrEmpty(u.nome))

This code simply check if the name field of the u object is not an empty/null string.

Ok this is very clear for me, but what can I do to check it if a field is not a string but is DateTime object?

Pooja Malohtra
Pooja Malohtra

Total Post:47

Posted on    February-10-2015 5:51 AM

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)






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

 DateTime? dat = null;

 if (!dat.HasValue)




Don't want to miss updates? Please click the below button!

Follow MindStick