In VB.NET, is there a way to set a DateTime
variable to "not set"? And why is it possible to set a DateTime
to Nothing
, but not possible to check if it is Nothing
? For example:
Dim d As DateTime = Nothing
Dim boolNotSet As Boolean = d Is Nothing
The second statement throws this error:
'Is' operator does not accept operands of type 'Date'. Operands must be reference or
nullable types.
You can check this like below :
Some examples on working with nullable
DateTime
values.(See Nullable Value Types (Visual Basic) for more.)
Also, on how to check whether a variable is null (from Nothing (Visual Basic)):