I find dates to be a pain to work with in .Net. The main
problem is that if you set the date to Nothing it is not
Nothing. Does anyone have a good solution for testing if
a date parameter to a Sub is Nothing?

*$#&% Date by Nick

Nick
Tue Dec 02 23:16:56 CST 2003

> The main
>problem is that if you set the date to Nothing it is not
>Nothing.

System.DateTime is a value type, so it can't be set to
nothing.

> Does anyone have a good solution for testing if
>a date parameter to a Sub is Nothing?
>

There are a couple of options:

1. Use the nullable types in System.Data.SqlTypes.
2. Use a third-party library like Nullable Types. (I
think this project lives on CodeProject).
3. Use a "special" DateTime like 1 Jan 1900 to signify
nullability.


Nick Wienholt, MVP
Maximizing .NET Performance
http://www.apress.com/book/bookDisplay.html?bID=217
Sydney Deep .NET User Group www.sdnug.org


Re: *$#&% Date by Robert

Robert
Wed Dec 03 00:49:04 CST 2003

What about just using the default value ("00:00:00.0000000, January 1,
0001", or 0 ticks) as the "special" type? It seems a bit more
understandable then using a special "magic number" for the value.

Dim dt as DateTime
...

If dt.Ticks() = 0 then
... (it's not initialized)
Else
' Reset dt to zero (default value)
dt = New System.DateTime
End If

(Air code.)


"Nick Wienholt" <goyousharks@hotmail.com> wrote in message
news:00cd01c3b95c$ab8cd850$a001280a@phx.gbl...
> > The main
> >problem is that if you set the date to Nothing it is not
> >Nothing.
>
> System.DateTime is a value type, so it can't be set to
> nothing.
>
> > Does anyone have a good solution for testing if
> >a date parameter to a Sub is Nothing?
> >
>
> There are a couple of options:
>
> 1. Use the nullable types in System.Data.SqlTypes.
> 2. Use a third-party library like Nullable Types. (I
> think this project lives on CodeProject).
> 3. Use a "special" DateTime like 1 Jan 1900 to signify
> nullability.
>
>
> Nick Wienholt, MVP
> Maximizing .NET Performance
> http://www.apress.com/book/bookDisplay.html?bID=217
> Sydney Deep .NET User Group www.sdnug.org
>



Re: *$#&% Date by Jagan

Jagan
Wed Dec 03 01:25:32 CST 2003

Best option is to set the date to System.DateTime.MinValue and check the
date against it.

Thanks,
Jagan Mohan

"Jeff" <anonymous@discussions.microsoft.com> wrote in message
news:072001c3b942$8b9e18c0$a101280a@phx.gbl...
> I find dates to be a pain to work with in .Net. The main
> problem is that if you set the date to Nothing it is not
> Nothing. Does anyone have a good solution for testing if
> a date parameter to a Sub is Nothing?
>
>



Re: *$#&% Date by Nick

Nick
Wed Dec 03 04:06:13 CST 2003

Yep - that will do. This is still just another mutually agreed upon date
that is read as null while still being a valid date. Probably a better
choice that 1 Jan 1900.

Nick

"Robert Jacobson" <rjacobson_at_oddpost_com@nospam.com> wrote in message
news:e367QmWuDHA.4060@TK2MSFTNGP11.phx.gbl...
> What about just using the default value ("00:00:00.0000000, January 1,
> 0001", or 0 ticks) as the "special" type? It seems a bit more
> understandable then using a special "magic number" for the value.
>
> Dim dt as DateTime
> ...
>
> If dt.Ticks() = 0 then
> ... (it's not initialized)
> Else
> ' Reset dt to zero (default value)
> dt = New System.DateTime
> End If
>
> (Air code.)
>
>
> "Nick Wienholt" <goyousharks@hotmail.com> wrote in message
> news:00cd01c3b95c$ab8cd850$a001280a@phx.gbl...
> > > The main
> > >problem is that if you set the date to Nothing it is not
> > >Nothing.
> >
> > System.DateTime is a value type, so it can't be set to
> > nothing.
> >
> > > Does anyone have a good solution for testing if
> > >a date parameter to a Sub is Nothing?
> > >
> >
> > There are a couple of options:
> >
> > 1. Use the nullable types in System.Data.SqlTypes.
> > 2. Use a third-party library like Nullable Types. (I
> > think this project lives on CodeProject).
> > 3. Use a "special" DateTime like 1 Jan 1900 to signify
> > nullability.
> >
> >
> > Nick Wienholt, MVP
> > Maximizing .NET Performance
> > http://www.apress.com/book/bookDisplay.html?bID=217
> > Sydney Deep .NET User Group www.sdnug.org
> >
>
>