SSIS Convert VARCHAR to DATE

SHREERAAMAA 1 Reputation point
2022-02-09T09:48:56.827+00:00

Good day,

I am using SSIS.

Data source is "Flat File Source"

Issue column name: [Years]

Data in this column [Years] shows only Years like 2000, 2010, 2011, 2021, 2222

Target is SQL Server table. In SQL Server target table [Years] column data type is "Date"

Can't move data from Flat File source to SQL Server target because of the Data type issue.

Please help

Thank you

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,490 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 25,386 Reputation points
    2022-02-09T13:35:11.08+00:00

    Hi @SHREERAAMAA ,

    So you have missing month and day to make a year it into a legit date.
    How about (DT_DBDATE)(CONCAT([Year], "-01-01"))

    0 comments No comments

  2. SHREERAAMAA 1 Reputation point
    2022-02-09T13:50:30.14+00:00

    Thank you for your response.

    Basically, [Years] source column data type is [DT_STR] and would like to push this data as is to Target table, SQL Server target column data type is DATE.

    Thank you


  3. ZoeHui-MSFT 34,581 Reputation points
    2022-02-10T02:06:53.79+00:00

    Hi @SHREERAAMAA ,

    If your source data format is yyyy-MM-dd and you want to convert it to DATE, you may add the Derived Column with below code.

    (DT_DBDATE)datecolumn  
    

    And then you may load it to SQL Server table.

    I would like to get YEAR from there.

    However I could not get the meaning of this, what result do you want to get? Could you please explain it with more details?

    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.