How to check if it is zero datetime in c#? What I mean zero datetime is: 01.01.0001 00:00:00
Use model. myDate. HasValue. It will return true if date is not null otherwise false.
The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar. MinValue defines the date and time that is assigned to an uninitialized DateTime variable. The following example illustrates this. C# Copy.
You'll want to check against DateTime.MinValue
More info here
You should check against default(DateTime)
The value of that is the same as DateTime.MinValue
but formally default(T)
is better. It is more readable and more in line with default(int)
, which is 0
and very different from int.MinValue
.
In a generic class, default(T)
works for DateTime as it does for all built-in value types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With