IsDate function is Vb.Net

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

    IsDate function is Vb.Net

    IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the function?
    What is the other way of checking the same functionality? Is there any other
    know issue with the date function.
    ..Net 1.1 Framework.
    I know alternative way of checking the same "If TypeOf MyVariable Is
    DateTime Then"
    Thanks,
    Smith


  • Armin Zingler

    #2
    Re: IsDate function is Vb.Net

    "Peter Smith" <Peter_Smith@ho tmail.com> schrieb[color=blue]
    > IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the
    > function? What is the other way of checking the same functionality?
    > Is there any other know issue with the date function.
    > .Net 1.1 Framework.
    > I know alternative way of checking the same "If TypeOf MyVariable Is
    > DateTime Then"[/color]


    I don't see a bug. It is a valid date. It's the first of January. The year
    is 2005 because it is not specified.


    Armin

    Comment

    • Peter Smith

      #3
      Re: IsDate function is Vb.Net

      Then what about this?
      IsDate("01/2005"). This is also january first 2005?
      Thanks,
      Smith


      "Armin Zingler" <az.nospam@free net.de> wrote in message
      news:uIzTEaXjFH A.2920@TK2MSFTN GP14.phx.gbl...[color=blue]
      > "Peter Smith" <Peter_Smith@ho tmail.com> schrieb[color=green]
      > > IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the
      > > function? What is the other way of checking the same functionality?
      > > Is there any other know issue with the date function.
      > > .Net 1.1 Framework.
      > > I know alternative way of checking the same "If TypeOf MyVariable Is
      > > DateTime Then"[/color]
      >
      >
      > I don't see a bug. It is a valid date. It's the first of January. The year
      > is 2005 because it is not specified.
      >
      >
      > Armin
      >[/color]


      Comment

      • Tom Shelton

        #4
        Re: IsDate function is Vb.Net

        In article <uteIx1WjFHA.28 52@TK2MSFTNGP14 .phx.gbl>, Peter Smith wrote:[color=blue]
        > IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the function?
        > What is the other way of checking the same functionality? Is there any other
        > know issue with the date function.
        > .Net 1.1 Framework.
        > I know alternative way of checking the same "If TypeOf MyVariable Is
        > DateTime Then"
        > Thanks,
        > Smith
        >
        >[/color]

        As Armin suggests, this is not a bug. Most likely, though I haven't
        really bothered to check, the IsDate function most is a wrapper
        for the DateTime.Parse function. And, if you read the remarks on this
        function in the documentation, I would expect this behavior.

        Basically, it says that the DateTime.Parse function uses the information
        in the DateTimeFormatI nfo for the current culture. As it parses, it
        will FILL in any missing values (month, day, year) with the
        values from the current date... Meaning that, the DateTime.Parse will
        turn your string:

        "01/01" into a date of "01/01/05". And that, is a valid date.

        --
        Tom Shelton [MVP]

        Comment

        • Tom Shelton

          #5
          Re: IsDate function is Vb.Net

          In article <u6U5cfXjFHA.12 04@TK2MSFTNGP12 .phx.gbl>, Peter Smith wrote:[color=blue]
          > Then what about this?
          > IsDate("01/2005"). This is also january first 2005?
          > Thanks,
          > Smith
          >[/color]

          See my previous post... Esentially, DateTime.Parse will interpret that
          as January 20, 2005 (basically, adding todays day in). Again, it will
          return a valid date, so the IsDate Function will return true.

          --
          Tom Shelton [MVP]

          Comment

          • Tom Shelton

            #6
            Re: IsDate function is Vb.Net

            In article <uteIx1WjFHA.28 52@TK2MSFTNGP14 .phx.gbl>, Peter Smith wrote:[color=blue]
            > IsDate("01/01") in Vb.Net is returning TRUE. Is it a bug in the function?
            > What is the other way of checking the same functionality? Is there any other
            > know issue with the date function.
            > .Net 1.1 Framework.
            > I know alternative way of checking the same "If TypeOf MyVariable Is
            > DateTime Then"
            > Thanks,
            > Smith
            >
            >[/color]

            One more note... If this is a problem for you - you could always write a
            replacement using DateTime.ParseE xact. ParseExact will only return a
            date if the date is in the specified format. So, in psuedo code it
            would look something like:

            public function myIsDate (date as string) as boolean
            try
            datetime.parsee xact (....)
            return true
            catch
            return false
            end try
            end fuction

            --
            Tom Shelton [MVP]

            Comment

            • Armin Zingler

              #7
              Re: IsDate function is Vb.Net

              "Peter Smith" <Peter_Smith@ho tmail.com> schrieb[color=blue]
              > Then what about this?
              > IsDate("01/2005"). This is also january first 2005?[/color]

              Yes:
              Msgbox CDate("01/2005")

              Tom's reply answers why.

              If you don't like the flexibilty of the function - you are not the only
              one - you can write one on your own (or find one for free).


              Armin



              Comment

              Working...