Converting to ISO 8601 Format

R

Roshawn Dawson

Hi,

I'm reading timestamp values from some log files. I need to merge the date and time values together
in ISO-8601 format.

I've loaded the date and time values into a dataset successfully. Putting them together and
formatting them in the proper format is troublesome for me.

This is what I have:

For i = 0 to dt.Rows.Count-1
Dim ddt As DateTime = dt.Rows(i).Item(0) & dt.Rows(i).Item(1)
dim str as string = ddt.ToString("YYYY-MM-DDThh:mm:ssTZD")
'... data omitted
Next

I always get an error with the above code. Can anyone help me?

Thanks,
Roshawn
 
A

Armin Zingler

Roshawn Dawson said:
I'm reading timestamp values from some log files. I need to merge
the date and time values together in ISO-8601 format.

I've loaded the date and time values into a dataset successfully. Putting
them together and formatting them in the proper format is
troublesome for me.

This is what I have:

For i = 0 to dt.Rows.Count-1
Dim ddt As DateTime = dt.Rows(i).Item(0) & dt.Rows(i).Item(1)

- & is an operator to connect strings
- What's in Item(0) and Item(1)?
- The result of & is a string. You can not store the string
in a DateTime variable.
dim str as string = ddt.ToString("YYYY-MM-DDThh:mm:ssTZD")
'... data omitted
Next

I always get an error with the above code. Can anyone help me?


http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdatetimeformatstrings.asp


Armin
 
C

Cor Ligthert [MVP]

Roshawn,
dim str as string = ddt.ToString("YYYY-MM-DDThh:mm:ssTZD")

The cases are extremely important in the paterns.

yyyy is year in 4 digits. YYYY means nothing.
MM is month in 2 digits mm is minutes in 2 digits.
dd is day in two digits.
d and nothing more is standard local short date format

I assume you find it now?

Cor
 
H

Herfried K. Wagner [MVP]

Roshawn Dawson said:
I'm reading timestamp values from some log files. I need to merge the
date and time values together in ISO-8601 format.

I've loaded the date and time values into a dataset successfully. Putting
them together and formatting them in the proper format is troublesome for
me.

This is what I have:

For i = 0 to dt.Rows.Count-1
Dim ddt As DateTime = dt.Rows(i).Item(0) & dt.Rows(i).Item(1)

'ddt = Date.Parse(...)' or 'ddt = Date.ParseExact(...)'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top