best way to tell if a date is not assigned?

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I want to tell if a date is invaid (not assigned yet)

right now i am doing this

dim aDate as datetime


if aDate.date = #12:00:00 AM#
' not assigned
else
'assigned
end if

which seems to work, but is this the best way to do this?
 
I would compare it with DateTime.MinValue instead of hardcoding what you
have there.
 
If you are using .NET 1.x, you have to use a magic value as you are doing.
You can use Date.MinValue since it is unlilely that you use it.

If you are using .NET 2.0 you can use the new nullable value types:

Dim dtDate As Nullable(Of Date)

If dtDate.HasValue Then
MessageBox.Show(dtDate.Value.ToString)
Else
MessageBox.Show("No date")
End If

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
wow didn't know abou the nullable types... definatly going to have to look
into that... now if the controls just were nullable like in a date time
picker and such...
 
Hi Brian,

Nullable types are new in .NET 2.0 using the new generics (Of T)
capabilities. In .NET 1.x you had to use magic values or implement your own
NullableDate type (there were some implementations out there). For backwards
compatibility the controls may not accept nullable types, but you can extend
them easily with a user control and a new property. The datetime picker has
a ShowCheckbox property or similar.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
Back
Top