DateTime null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

What's the correct code for checking if a DateTime control is empty or not
filled in with a date?

Thanks,

JJ
 
JJ said:
What's the correct code for checking if a DateTime control is empty
or not filled in with a date?

Not sure what you mean by a DateTime control, as DateTime *isn't* a
control - however, there's no concept of a DateTime not being filled
in, any more than there is a concept of an int not being filled in. You
*may* be able to use a special value (eg DateTime.MinValue) as "not
provided" depending on your application.

Alternatively, you could encapsulate the DateTime in a reference type.
 
ok the DateTimePicker Control is what i'm using if u want to get technical
about it.
I want to know if someone has not entered a date into it.

JJ
 
Incidentally, how would you set the value to null in the first place? I
would recommend that you handle the click or valuechanged event to indicate
user interaction.
BTW: The venerable Mr. Skeet was exactly right in pointing you towards
reference type, not to mention that he similar to the C# forum what
Alexander, Kim, Brian, and Igor are to the ATL forum (sorry
gurus-not-mentioned, I'm very bad on names). Suggesting that a person is
being too technical in a technical forum may be ill-received by some people.
Best regards.

HTH,

mk
 
What I meant was there is a datetimepicker control. Sorry for leaving off the
picker part but I figured most people would know that I'm probably talking
about the datetimepicker control.
 
JJ said:
What I meant was there is a datetimepicker control. Sorry for leaving off the
picker part but I figured most people would know that I'm probably talking
about the datetimepicker control.

As far as I can see, a DateTimePicker is filled with the current
date/time until the user chooses something, so there's no concept of
"null" there either.
 
What I meant was there is a datetimepicker control. Sorry for leaving off the
picker part but I figured most people would know that I'm probably talking
about the datetimepicker control.

With the standard DateTimePickerControl a user does not have the
possibility to enter no date. So you always have a valid DateTime value in
the DateTimePickerControl.

If you need a DateTimePickerControl that allows the user to empty the
control, have a look at this solution:
http://www.codeproject.com/cs/miscctrl/NullableDateTimePicker.asp
 
Back
Top