Converting date formats

M

Mika M

Hi!

I'm reading CSV-file using OleDB provider with SQL-select command and
it's working fine. Anyway CSV-file contains "field" containing date
values like 20060825, and I'd like to convert it into datetime format
when reading it into DataTable like #8/25/2006#. How to do this?
Propably I have to change select-query somehow converting this field
into datetime format.

Now I doing it in my code like...

Dim dte As DateTime = Date.ParseExact(dr("MyDate").ToString(),
"yyyyMMdd", Nothing)

....but I'd like to get rid of this way doing it already using sql-query
when importing data into DataTable.
 
Z

zacks

Mika said:
Hi!

I'm reading CSV-file using OleDB provider with SQL-select command and
it's working fine. Anyway CSV-file contains "field" containing date
values like 20060825, and I'd like to convert it into datetime format
when reading it into DataTable like #8/25/2006#. How to do this?
Propably I have to change select-query somehow converting this field
into datetime format.

Now I doing it in my code like...

Dim dte As DateTime = Date.ParseExact(dr("MyDate").ToString(),
"yyyyMMdd", Nothing)

...but I'd like to get rid of this way doing it already using sql-query
when importing data into DataTable.

Something like:

'#' + cast(cast(substring(MyDate, 5, 2) as int) as varchar) + '/' +
substring(MyDate, 7, 2) + '/' + left(MyDate, 4) + '#'

maybe?
 

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