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

Date Conversion

Status
Not open for further replies.

tman24m

Programmer
May 21, 2001
93
US
I use DTS to import data from our AS400 servers. When the date fields are imported, they come in as a decimal data type and look like 20020315. I want to convert them to a datetime data type. I've tried using Transformation to convert but am having no luck.

I have some jobs that are daily and it sure would be nice if I could automate this.

thanks
 
You may use following conversions:
SELECT CAST( CAST(20020315 AS VARCHAR) AS DATETIME ) (which display 2002-03-15 00:00:00.000)
or
SELECT CAST( CAST( AS400DateField AS VARCHAR) AS DATETIME )

Succes !
 
that doesn't seem to work for me. I tried it in query analyzer and got the following

Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.

Any other suggestions?
 
Anything in this you can use?.......
I tried this in QA and it seems to work fine.

bp

declare @myInput int
set @myInput = 20011201

declare @myDate datetime
set @myDate = convert(datetime,cast(@myInput as varchar))

select @mydate

 
Hi tman24m,
Assuming that from AS400 the dates are coming in yyyymmdd format you can convert them in to date format by using

Select Convert(datetime, str(20020315))

this will convert your decimal date in 20020315 format to a datetime format.

I tried this on SQL 7 & SQL 2000 & this works fine.

Hope this helps,

Mukund.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top