How to convert varchar column into timestamp format with Data Conversion(SSIS Data Flow Item)?

I am getting date column in the source file(.csv) like  20080727063005. I need to load this value into Sql Server table as Datetime data type column.(yyyy-mm-dd hh:mi:ss FORMAT)  Hope i can do it with Data Conversion . But i am new to SSIS. So can you please tell me how to solve this problem with Data conversion? or Is there  any other easy method please let me know.
Thanks in advance.
PKTGAsked:
Who is Participating?
 
HoggZillaCommented:
Use the SSIS Transformation, Derived Column.
http://msdn.microsoft.com/en-us/library/ms141069.aspx
 With the derived column you use an expression to parse the string into a datetime string and declare it as a DT_DATE data type. The following screen shot shows the start.

derived-column.bmp
0
 
MohammedUCommented:
DECLARE @dt Varchar(30)

SET @dt =  '20080727063005'
 

SELECT CONVERT(datetime,
       LEFT(CAST(CAST(@dt as BigInt) as varchar(14)),8)+' '+
       SUBSTRING(CAST(CAST(@dt as BigInt) as varchar(14)),9,2)+':'+
       SUBSTRING(CAST(CAST(@dt as BigInt) as varchar(14)),11,2)+':'+
       SUBSTRING(CAST(CAST(@dt as BigInt) as varchar(14)),13,2)
       )
0
 
Anthony PerkinsCommented:
Or simply :)

Declare @Dat varchar(14)
Set @Dat = '20080727063005'

Select CONVERT(datetime, STUFF(STUFF(STUFF(STUFF(STUFF(@Dat, 5, 0, '-'), 8, 0, '-'), 11, 0, ' '), 14, 0, ':'), 17, 0, ':'), 120)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
PKTGAuthor Commented:
Thanks for the feedback . I did it with below script
SUBSTRING(column0,1,4)+'-'+
SUBSTRING(column0,5,2)+'-'+
SUBSTRING(column0,7,2)+' '+
SUBSTRING(column0,9,2)+':'+
SUBSTRING(column0,11,2)+':'+
SUBSTRING(column0,13,2) as STRT_TMST  
Now i am in the situation to do it via SSIS. I can use this scrip in Exec SQL  task. But Can you please tell me is it possible to do with Data Conversion Task? Thanks.
0
 
MohammedUCommented:
I believe you can...but I have not tested it...
0
 
HoggZillaCommented:
Here is the expression
SUBSTRING(DateString,1,4) + "/" + SUBSTRING(DateString,5,2) + "/" + SUBSTRING(DateString,7,2) + " " + SUBSTRING(DateString,9,2) + ":" + SUBSTRING(DateString,11,2) + ":" + SUBSTRING(DateString,13,2)
Here is the return values
DateString,DATE
20080727063005,2008/07/27 06:30:05
0
 
PKTGAuthor Commented:
I am converting flatfile datestring to another flat file with SSIS package. With drived column , i gave the below expression with DT_Date datatype.

SUBSTRING(DateString,1,4) + "-" + SUBSTRING(DateString,5,2) + "-" + SUBSTRING(DateString,7,2) + " " + SUBSTRING(DateString,9,2) + ":" + SUBSTRING(DateString,11,2) + ":" + SUBSTRING(DateString,13,2)  
I expect it will return datestring value like 2008-07-22 21:58:36  but it shows 7/22/2008 9:58:36 PM.
But I need to display like 2008-07-22 21:58:36  . Can you please advise me how to fix this? Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.