Home All Groups Group Topic Archive Search About

Assigning a Null to Datetime Variable or Object

Author
12 Apr 2005 3:46 PM
Solution Seeker
Hi,

I need a solution to assign a Null to a Datetime Variable / Object.

Am willing to know whether it is possible?

I will appreciate you if any one knows the solution for it .

The Situation is

I like to store a Date in the Object when the User enters the Date.

If he doesn't enters anything then i like to store Null inorder to use that
in my Validation.

Note:
  I have n't used the Date time Control for entering the Date rather i used
the Textbox to enter the Date. But the Object's Date Type is Datetime.

Let me know if anyone helps me

thanks
Solution Seeker

Author
12 Apr 2005 4:32 PM
Oenone
Solution Seeker wrote:
> I like to store a Date in the Object when the User enters the Date.
> If he doesn't enters anything then i like to store Null inorder to
> use that in my Validation.

I have approached this by using "DateTime.MinValue" as a placeholder for a
null date. Anywhere I want to store a blank date value in a Date variable,
I'll store DateTime.MinValue. Anywhere I want to check to see whether a date
is blank or not I'll compare it to DateTime.MinValue.

This has worked very well in my application.

Hope that helps,

--

(O)enone
Author
12 Apr 2005 5:56 PM
Herfried K. Wagner [MVP]
"Solution Seeker" <Solution See***@discussions.microsoft.com> schrieb:
> I need a solution to assign a Null to a Datetime Variable / Object.

'Date' is a value type and cannot be 'Nothing'. Take a look at the
'SqlDateTime' data type, which supports 'NULL' values.  .NET 2.0 will
support nullable types.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>