Share via

convert YYYYMMDD to datetime in ssis

Naresh y 146 Reputation points
2022-02-14T13:55:04.88+00:00

Hi I have date filed in my source column of string data type
datecolumn
20210521
20211005
i want to convert this value to datetime which is in my target table ,format like
2021-05-21 00:00:00.000
2021-10-05 00:00:00.000

i tried converting in the sql sselect script and try to map to the destination but its not working

please help me to define the derived column exp in ssis ,how to write the exp to write to change this date column values in ssis? please suggest

SQL Server Integration Services
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


5 answers

Sort by: Most helpful
  1. Kumar, Anil 0 Reputation points
    2023-02-27T11:43:25.8533333+00:00

    Use tryConvert function

    Was this answer helpful?

    0 comments No comments

  2. Olaf Helper 47,616 Reputation points
    2022-02-15T06:44:50.223+00:00

    I tried using the data conversion but its failing

    And which error message do you get (we can't guess that)?

    Was this answer helpful?

    0 comments No comments

  3. ZoeHui-MSFT 41,551 Reputation points
    2022-02-15T01:22:23.05+00:00

    Hi @Naresh y

    Have you check your previous question in Microsoft Q&A?

    how-to-convert-the-fixed-width-date-column-into-th.html

    1. You may add the Derived Column with below code. (DT_DBTIMESTAMP)(SUBSTRING(datecolumn,1,4) + "-" +SUBSTRING(datecolumn,5,2) + "-" + SUBSTRING(datecolumn,7,2))

    2.You may add the Data Conversion. Choose DT_DBTIMESTAMP as datatype.

    And then Go to Input and Output Properties---Expand Data Conversion Output and click on the date column---Set FastParse to True in the Custom Properties.

    If this do not help, you may show the error message for us to do more analysis.

    If your issue has been resolved please mark the reply as answer so other user with similar problem could see this easier. :)

    Regards,

    Zoe


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


  4. Naresh y 146 Reputation points
    2022-02-14T14:42:58.767+00:00

    I tried using the data conversion but its failing
    can you help with the expression

    Was this answer helpful?

    0 comments No comments

  5. Olaf Helper 47,616 Reputation points
    2022-02-14T14:14:04.493+00:00

    In T-SQL

    select CONVERT(datetime, '20210521', 112);  
    

    See CAST and CONVERT (Transact-SQL)

    For SSIS see Convert Data Type with Data Conversion Transformation

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.