---
title: "How to validate if a DateTime field is not null / empty?"  
description: "How to validate if a DateTime field is not null / empty?"  
author: "Anonymous User"  
published: 2015-02-10  
updated: 2015-02-10  
canonical: https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to validate if a DateTime field is not null / empty?

I found something like:

**if (![String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp).IsNullOrEmpty(u.nome))**

This [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) simply [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) the [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) of the u object is not an empty/[null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp) 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](https://www.mindstick.com/forum/1185/how-can-i-work-with-datetimepicker-control) object?

## Replies

### Reply by Anonymous User

If you declare a DateTime, then the default value is DateTime.MinValue, and hence you have to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) 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 }
```


---

Original Source: https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
