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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to date.parse from ISO 8601 date format? 2

Status
Not open for further replies.

ttdobj

Technical User
Sep 30, 2002
63
GB
We are taking in a text file that has the dates formated in the ISO 8601 date standard. FOr example: yyyy-mm-dd

How do I parse this value?

I wondered about using cultures, but I cannot find a way of specifying that the culture is an ISO date standard.

Can any one help ?

Ta

John
 
Okay, so now I realise that date.tryparse recognizes it as the ISO standard format anyway.
do'h!
 
Haven't used TryParse yet. Would you mind posting a bit of your code? Thank!
 
Here goes
Code:
TempDate as Date
Dim MyDate as String   'The value to be parsed.
' Validate the Quantity.
If Date.TryParse(MyDate, TempDate) = True Then
    ' Validation succeeded.
    MessageBox.Show("The date: " & MyDate & " is valid")

    ' TempDate now holds the parsed date.
Else
    ' Validation failed.
    MessageBox.Show("The date: " & MyDate & " is not valid")
End If
 
SBendBuckeye TryParse is available for a variety of type.

It returns a Boolean and takes two parameters, the string representation of what you want to parse and a By Ref to the target variable.

It is a shared function of the relevant Class as in the following examples:

Code:
		Dim strDate As String = "31/05/2007"
		Dim strInteger As String = "12345"
		Dim strDouble As String = "123.45"

		Dim dateDate As Date = Nothing
		Dim integerInteger As Integer = Nothing
		Dim doubleDouble As Double = Nothing

		If Not Date.TryParse(strDate, dateDate) Then
			MessageBox.Show(strDate + " is not a valid date")
		Else
			MessageBox.Show(strDate + " = " + dateDate.ToString)
		End If
		If Not Integer.TryParse(strInteger, integerInteger) Then
			MessageBox.Show(strInteger + " is not a valid integer")
		Else
			MessageBox.Show(strInteger + " = " + integerInteger.ToString)
		End If
		If Not Double.TryParse(strDouble, doubleDouble) Then
			MessageBox.Show(strDouble + " is not a valid double")
		Else
			MessageBox.Show(strDouble + " = " + doubleDouble.ToString)
		End If


Hope this helps.

[vampire][bat]
 
SBendBuckeye as you are monitoring this thread, just a quick question for you.

re the scrollbars in an RTB, did you find a better method as I am currently using the one I suggested, but am open to improvement as I'm not over-impressed with it.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top