PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET best way to tell if a date is not assigned?

Reply

best way to tell if a date is not assigned?

 
Thread Tools Rate Thread
Old 14-03-2006, 09:26 PM   #1
Brian Henry
Guest
 
Posts: n/a
Default best way to tell if a date is not assigned?


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?


  Reply With Quote
Old 14-03-2006, 09:32 PM   #2
Marina Levit [MVP]
Guest
 
Posts: n/a
Default Re: best way to tell if a date is not assigned?

I would compare it with DateTime.MinValue instead of hardcoding what you
have there.

"Brian Henry" <nospam@nospam.com> wrote in message
news:exCS236RGHA.4300@TK2MSFTNGP14.phx.gbl...
>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?
>



  Reply With Quote
Old 15-03-2006, 11:37 AM   #3
Carlos J. Quintero [VB MVP]
Guest
 
Posts: n/a
Default Re: best way to tell if a date is not assigned?

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


"Brian Henry" <nospam@nospam.com> escribió en el mensaje
news:exCS236RGHA.4300@TK2MSFTNGP14.phx.gbl...
>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?
>



  Reply With Quote
Old 15-03-2006, 12:23 PM   #4
Brian Henry
Guest
 
Posts: n/a
Default Re: best way to tell if a date is not assigned?

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...


  Reply With Quote
Old 15-03-2006, 01:16 PM   #5
Carlos J. Quintero [VB MVP]
Guest
 
Posts: n/a
Default Re: best way to tell if a date is not assigned?

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


"Brian Henry" <nospam@nospam.com> escribió en el mensaje
news:O7C19sCSGHA.524@TK2MSFTNGP10.phx.gbl...
> 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...
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off