Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Isdate returns true

Status
Not open for further replies.

sandylou

Programmer
Jan 18, 2002
147
0
0
US
Hi i have a date I am trying to see if is valid 1/106


When I use isdate, it returns true. is there another easy way to check if this is valid other than breaking down the string into parts?

 
I have to ask, what's wrong with January 106, it is a valid date. I guess the question is what do you consider a valid date?

You can use DateTime.ParseExact() but you will have to decide what a valid format is, in this example you will need to use a two digit month and two digit year for it to be valid.

Not a great solution but a solution none the less...

Code:
  Dim dt As DateTime
        Dim Culture = New CultureInfo("en-GB", True)

        Try
            dt = DateTime.ParseExact("01/106", "MM/yy", Culture, Globalization.DateTimeStyles.NoCurrentDateDefault)
            MessageBox.Show("Valid Date")
        Catch ex As Exception
            MessageBox.Show("Not a valid Date")
        End Try
 
My suggestion is to always force month, day, and year for dates. Either tacking it on when accepting the dates or just before you start working with the date.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top