Solved

IsDate doesn't work properly in VB.net 2008 -- What else can I use?

Posted on 2009-05-16
3
466 Views
Last Modified: 2012-05-07
Okay, So I have a CSV, basicly it has different functions. I just converted from VB6 to .net 2008, However.. There are some difficulties with the IsDate function now.

Isdate in VB6 would come back true if:

05/05/2008
05/05/2008 05:05:02
05/05/2008 12:00:00PM

And I think some basic ones like May 05, 2008, or something like that.

Anyways. The string its searching can have different formats, thus I need to CHECK to make sure it is a date, this was great in VB6, however, .NET returns a string like 05/05/2008 05:05:02 to FALSE. I am not sure why either.

Basicly the function coding was basic for it:

                        If validfound = -1 Then
                            For i = 0 To UBound(marray)
                                If IsDate(marray(i)) Then
                                    validfound = i
                                    Exit For
                                End If
                            Next
                        End If

And it was fine, but now I am having issues. any suggesetions so that it works for all dates and if theres a time included for that too?

It can however use short or long dates too, like 5/5/2008 or 05/05/2008 or 5/5/08, for example.. Stuff like that. Was okay previously.
0
Comment
Question by:Valleriani
  • 2
3 Comments
 
LVL 7

Author Comment

by:Valleriani
ID: 24403480
Ok I found the problem, for example:

30/4/2008 will work
but 4/30/2008 will not.

How can I solve this?
0
 
LVL 7

Author Comment

by:Valleriani
ID: 24403490
And please keep in mind sometimes dates can be November, 19 2008 for example.. Or have time in them too..
0
 
LVL 4

Accepted Solution

by:
TMarkham1 earned 500 total points
ID: 24403892
Look into the DateTime.TryParse method. It takes in a String and a reference to a DateTime object as parameters. If it can parse the string value successfully, it will place the correct date and time in the DateTime reference passed in. It returns a boolean value so yo know whether or not the string value is in fact a date. It is also overloaded so you can setup your own format on which to parse.
Dim strDate as String = '5/05/2009 09:31:24'
Dim DateVal as DateTime
 
If DateTime.TryParse(strDate, DateVal) Then
   'DateVal is set to 05/05/2009 09:31:24
End If

Open in new window

0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question