• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2800
  • Last Modified:

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.
0
PKTG
Asked:
PKTG
  • 2
  • 2
  • 2
  • +1
3 Solutions
 
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
 
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
MohammedUCommented:
I believe you can...but I have not tested it...
0
 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now