Excel MM/DD/YYYY Date Conversion Issues

Bobby P 231 Reputation points
2022-09-22T19:02:09.083+00:00

We have an Excel Data Colum CarrierInvoicedDate which has the format MM/DD/YYYY and exists in the Excel spreadsheet with a General format.

Our data pump to a SQL Server Table where we have CarrierInvoicedDate defined as a DATE Data Type is choking and resulting in...

"Invalid character value for cast specification"

Do we need to reformat this CarrierInvoicedDate Data Column in Excel prior to trying to pump the data to our SQL Server Table? And reformat it in Excel to what? Date?

Thanks in advance for your review and am hopeful for a reply.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,705 questions
Microsoft 365 and Office | Excel | For business | Windows
{count} votes

4 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 26,586 Reputation points
    2022-09-22T20:03:39.987+00:00

    Hi @Bobby P ,

    I would suggest to use Derived Column Transformation to convert MM/DD/YYYY into the yyyy-MM-dd format. After that SQL Server column with the DATE format will accept it without any problem.

    0 comments No comments

  2. ZoeHui-MSFT 41,496 Reputation points
    2022-09-23T01:56:31.67+00:00

    Hi @Bobby P ,

    In addition of using Derived Column Transformation, you may also go to advance editor for excel source-->input and output properties-->output column.

    Change the datatype to [DT-Date] or [DT_DBDATE].

    244082-image.png

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


  3. Bobby P 231 Reputation points
    2022-10-26T20:24:12.707+00:00

    So I indeed have database date [DT_DBDATE] as the Advanced Editor ==> Input and Output Properties ==> Excel Source Output ==> Output Columns [CarrierInvoicedDate] DataType and that doesn't work.

    I am adding in a Derived Column task for the [CarrierInvoicedDate] to try and convert MM/DD/YYYY to ISO format YYYY-MM-DD to Data Pump that to a SQL Server Table data column defined as a DATE type with the following Expression...

    (DT_DBDATE)(TOKEN( [CarrierInvoicedDate],"/",3) + "-" + TOKEN([CarrierInvoicedDate],"/",1) + "-" + TOKEN([CarrierInvoicedDate],"/",2))

    It is still failing on an error. Is my syntax correct? Do I also have to allow if my [CarrierInvoicedDate] has no data? Sooooo do I have to allow for NULLs in this expression and how do I do that.

    Also...Do I need to reset that Advanced Editor ==> Input and Output Properties ==> Excel Source Output ==> Output Columns [CarrierInvoicedDate] DataType back to String or something?

    Boy...I have pumped a lot of Excel spreadsheets into SQL Server Tables in the past...I just never remember this hassle between Excel format and SQL Server Date format before.

    Any help and clarification is GREATLY appreciated.

    0 comments No comments

  4. Bobby P 231 Reputation points
    2022-10-26T20:48:50.433+00:00

    Can anyone provide a Step-By-Step to do this simple Excel to SQL Server Date Conversion?

    Do I need to start a new thread here??

    0 comments No comments

Your answer

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