问题
I have a date 26.12.2019 (dd.mm.yyyy) in CSV which I'm trying to convert to 2019-12-26 using Derived Column in SSIS. I have used this expression but it does not seem to work.
(TRIM([Period Start Date]) == "") ? NULL(DT_DATE) : (DT_DATE)(SUBSTRING([Period Start Date],7,4) + "-" + SUBSTRING([Period Start Date],4,2) + "-" + SUBSTRING([Period Start Date],1,2))
How do I rewrite this expression to produce the correct output with a value of data type?
回答1:
When using DT_DATE data type, value is not saved in a specific format, it is shown based on your operating system regional settings. If you need to use a specific format, you can keep it as string as following:
(TRIM([Period Start Date]) == "") ? NULL(DT_WSTR,50) : (DT_WSTR,50)(SUBSTRING([Period Start Date],7,4) + "-" + SUBSTRING([Period Start Date],4,2) + "-" + SUBSTRING([Period Start Date],1,2))
来源:https://stackoverflow.com/questions/58610394/how-to-convert-string-in-format-dd-mm-yyyy-to-date-using-ssis-expression