无法使用 SSIS 中的表达式将字符串转换为 DateTime

Not able to convert string to DateTime using expression in SSIS

我在 SSIS 包中有 2 个变量,作为字符串的 CurrFile 和 DateTime 数据类型的 File_Dt。我想从 CurrFile 中提取 DateTime 并将其存储到 File_Dt 变量中。为此,我使用如下表达式:

(DT_DBDATE) SUBSTRING( @[User::CurrFile], 21,14 )

执行 SUBSTRING 后,值为 20190725001614。现在,我想将此值作为 DateTime 存储在 File_Dt 变量中。这样做时出现此错误。

Error code 0x80020005 occurred attempting to convert from data type DT_WSTR to data type DT_DBDATE.

您必须确保该字符串包含具有以下格式的数据时间值:yyyy-MM-dd HH:mm:ss。还可以使用 DT_DATEDT_DBTIMESTAMP 而不是 DT_DBDATE 尝试以下表达式:

(DT_DBTIMESTAMP) SUBSTRING( @[User::CurrFile], 21,4 ) + "-" +
SUBSTRING( @[User::CurrFile], 25,2 ) + "-" + 
SUBSTRING( @[User::CurrFile], 27,2 ) + " " +
SUBSTRING( @[User::CurrFile], 29,2 ) + ":" + 
SUBSTRING( @[User::CurrFile], 31,2 ) + ":" + 
SUBSTRING( @[User::CurrFile], 33,2 )