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.

--
Thanks in advance!

Mika

Re: Converting date formats by zacks

zacks
Fri Aug 25 07:24:18 CDT 2006


Mika M wrote:
> 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?