Setting Date/Time variable to nothing (empty)

trisolve

Newcomer
Joined
Nov 30, 2003
Messages
11
How do i set the date/time variable to nothing. e.g for string we could do as follows:
mystr = ""
but this doesn't work for datetime variable. Help please
thanks
trisolve
 
Because all value types resolve to reference types in the .NET
Framework, you can just set the variable to Nothing (in VB) or null
(in C#).
 
mocella, i tried your method but I don't think I understood it right. If you can give me an example that would be great.
Bucky, I tried setting the value to nothing but all it does is it sets the variable time to its default that is 12:00:00 AM. thanks
 
When you access a DateTime variable that has been set to
Nothing, then it will initialize and return the default value. Instead
of retrieving its value, just check to see if it's equal to Nothing.

Here x is the DateTime variable:
Visual Basic:
If x = Nothing Then
  ' x is set to default value
End If

Note that for reference types you use the Is keyword to compare
objects. For comparing a value type (x, the DateTime) with a
reference type (Nothing), as is the case here, you use =.
 
Back
Top