DateTime null

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JJ

    #1

    DateTime null

    Hi,

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

    Thanks,

    JJ
  • Jon Skeet [C# MVP]

    #2
    Re: DateTime null

    JJ <JJ@discussions .microsoft.com> wrote:[color=blue]
    > What's the correct code for checking if a DateTime control is empty
    > or not filled in with a date?[/color]

    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.MinVal ue) as "not
    provided" depending on your application.

    Alternatively, you could encapsulate the DateTime in a reference type.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Bruce Wood

      #3
      Re: DateTime null

      Or, you could wait for v2.0 of the Framework, at which point you can
      use "DateTime?"

      Comment

      • JJ

        #4
        Re: DateTime null

        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

        "Jon Skeet [C# MVP]" wrote:
        [color=blue]
        > JJ <JJ@discussions .microsoft.com> wrote:[color=green]
        > > What's the correct code for checking if a DateTime control is empty
        > > or not filled in with a date?[/color]
        >
        > 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.MinVal ue) as "not
        > provided" depending on your application.
        >
        > Alternatively, you could encapsulate the DateTime in a reference type.
        >
        > --
        > Jon Skeet - <skeet@pobox.co m>
        > http://www.pobox.com/~skeet
        > If replying to the group, please do not mail me too
        >[/color]

        Comment

        • mk

          #5
          Re: DateTime null

          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

          "JJ" wrote:
          [color=blue]
          > 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
          >
          > "Jon Skeet [C# MVP]" wrote:
          >[color=green]
          > > JJ <JJ@discussions .microsoft.com> wrote:[color=darkred]
          > > > What's the correct code for checking if a DateTime control is empty
          > > > or not filled in with a date?[/color]
          > >
          > > 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.MinVal ue) as "not
          > > provided" depending on your application.
          > >
          > > Alternatively, you could encapsulate the DateTime in a reference type.
          > >
          > > --
          > > Jon Skeet - <skeet@pobox.co m>
          > > http://www.pobox.com/~skeet
          > > If replying to the group, please do not mail me too
          > >[/color][/color]

          Comment

          • JJ

            #6
            Re: DateTime null

            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.

            "mk" wrote:
            [color=blue]
            > 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
            >
            > "JJ" wrote:
            >[color=green]
            > > 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
            > >
            > > "Jon Skeet [C# MVP]" wrote:
            > >[color=darkred]
            > > > JJ <JJ@discussions .microsoft.com> wrote:
            > > > > 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.MinVal ue) as "not
            > > > provided" depending on your application.
            > > >
            > > > Alternatively, you could encapsulate the DateTime in a reference type.
            > > >
            > > > --
            > > > Jon Skeet - <skeet@pobox.co m>
            > > > http://www.pobox.com/~skeet
            > > > If replying to the group, please do not mail me too
            > > >[/color][/color][/color]

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: DateTime null

              JJ <JJ@discussions .microsoft.com> wrote:[color=blue]
              > 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.[/color]

              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.

              --
              Jon Skeet - <skeet@pobox.co m>
              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

              If replying to the group, please do not mail me too

              Comment

              • Claudio Grazioli

                #8
                Re: DateTime null

                On Wed, 11 May 2005 13:59:15 -0700, JJ wrote:
                [color=blue]
                > 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.
                >[/color]

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

                If you need a DateTimePickerC ontrol that allows the user to empty the
                control, have a look at this solution:


                --
                Claudio Grazioli
                Our website about our photography and travel. Enjoy our picture galleries from around the world or read our blog about travel and photography


                Comment

                Working...