Assigning a Null to Datetime Variable or Object

G

Guest

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
 
O

Oenone

Solution said:
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,
 
H

Herfried K. Wagner [MVP]

Solution Seeker said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top