assign null value to datetime

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

    #1

    assign null value to datetime

    I want to assign a null value to a DateTime variable.How
    do i do that?

    Thanks
    Vince
  • Horatiu Ripa

    #2
    Re: assign null value to datetime

    MSDN:
    "Unlike reference types, it is not possible for a value type to contain the
    null value."

    DateTime is a value type.

    --
    Horatiu Ripa
    Software Development Manager
    Business Logic Systems LTD
    21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
    Phone/Fax: +40 264 590703
    Web: www.businesslogic.co.uk

    This email (email message and any attachments) is strictly confidential,
    possibly privileged and is intended solely for the person or organization to
    whom it is addressed. If you are not the intended recipient, you must not
    copy, distribute or take any action in reliance on it. If you have received
    this email in error, please inform the sender immediately before deleting
    it. Business Logic Systems Ltd accepts no responsibility for any advice,
    opinion, conclusion or other information contained in this email or arising
    from its disclosure.

    "vince" <anonymous@disc ussions.microso ft.com> wrote in message
    news:073f01c3ba 3a$88f51b20$a40 1280a@phx.gbl.. .[color=blue]
    > I want to assign a null value to a DateTime variable.How
    > do i do that?
    >
    > Thanks
    > Vince[/color]


    Comment

    • Jan Tielens

      #3
      Re: assign null value to datetime

      Since DateTime is a Value Type (not a Reference Type), so you can't assign
      null or Nothing to it. If you want to do something simelar, you could use
      the MinValue property:

      if(myDate == DateTime.MinVal ue)
      {
      //myDate is empty
      }

      Or you can use the Nullable Types library:
      open source, source code, freeware, shareware, programmer, developer, VB, Visual Basic, C++, C#, C Sharp, Oracle, Oracle8i, Oracle9i, VB 6, VB6, VB.NET, Visual Basic.NET, Visual Basic 6, Visual Studio, Visual Studio.NET, framework .net, dotNet, microsoft, oracle, OO, OOA, OOD, OOP, UML, unified modeling language


      Jan

      "vince" <anonymous@disc ussions.microso ft.com> wrote in message
      news:073f01c3ba 3a$88f51b20$a40 1280a@phx.gbl.. .[color=blue]
      > I want to assign a null value to a DateTime variable.How
      > do i do that?
      >
      > Thanks
      > Vince[/color]


      Comment

      • Ron McNulty

        #4
        Re: assign null value to datetime

        Sorry Vince, it is a value type, so it can't be null. I usually work around
        this by assigning DateTime.MinVal ue as the "null" value.

        Regards

        Ron

        "vince" <anonymous@disc ussions.microso ft.com> wrote in message
        news:073f01c3ba 3a$88f51b20$a40 1280a@phx.gbl.. .[color=blue]
        > I want to assign a null value to a DateTime variable.How
        > do i do that?
        >
        > Thanks
        > Vince[/color]


        Comment

        • Guest's Avatar

          #5
          assign null value to datetime

          You cannot assign null value to datetime because it's
          structure not a class. Stucture has to always has a value.

          Jan.
          [color=blue]
          >-----Original Message-----
          >I want to assign a null value to a DateTime variable.How
          >do i do that?
          >
          >Thanks
          >Vince
          >.
          >[/color]

          Comment

          • Horatiu Ripa

            #6
            Re: assign null value to datetime

            MSDN:
            "Unlike reference types, it is not possible for a value type to contain the
            null value."

            DateTime is a value type.

            --
            Horatiu Ripa
            Software Development Manager
            Business Logic Systems LTD
            21 Victor Babes str., 1st floor, 3400 Cluj-Napoca, Romania
            Phone/Fax: +40 264 590703
            Web: www.businesslogic.co.uk

            This email (email message and any attachments) is strictly confidential,
            possibly privileged and is intended solely for the person or organization to
            whom it is addressed. If you are not the intended recipient, you must not
            copy, distribute or take any action in reliance on it. If you have received
            this email in error, please inform the sender immediately before deleting
            it. Business Logic Systems Ltd accepts no responsibility for any advice,
            opinion, conclusion or other information contained in this email or arising
            from its disclosure.

            "vince" <anonymous@disc ussions.microso ft.com> wrote in message
            news:073f01c3ba 3a$88f51b20$a40 1280a@phx.gbl.. .[color=blue]
            > I want to assign a null value to a DateTime variable.How
            > do i do that?
            >
            > Thanks
            > Vince[/color]


            Comment

            Working...