How to convert string in format dd.mm.yyyy to date using SSIS expression?

谁说胖子不能爱 提交于 2021-01-27 20:56:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!