SSIS expression builder: convert date/time to Epoch timestamp

北城余情 提交于 2020-01-22 00:22:11

问题


I'm trying to build an expression to convert a date/time parameter to an Epoch timestamp that will be used in a Url's parameter string.

I figured that I would try GetDate() first, then substitute the actual parameter (@[$Package::endingDate]).

This syntax:

DATEDIFF("s", "19700101", GETDATE() )

produces:

The function "DATEDIFF" does not support the data type "DT_WSTR" for parameter number 2. The type of the parameter could not be implicitly cast into a compatible type for the function. To perform this operation, the operand needs to be explicitly cast with a cast operator.

This syntax:

DATEDIFF("s", (DT_WSTR)"19700101", GETDATE() )

produces:

Attempt to parse the expression "DATEDIFF("s", (DT_WSTR)"19700101", GETDATE() )" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

This syntax:

DATEDIFF("s", CAST("19700101" AS DT_WSTR), GETDATE() )

produces:

Attempt to parse the expression "DATEDIFF("s", CAST("19700101" as DT_WSTR), GETDATE() )" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

Is there a way to convert a date/time to an Epoch timestamp, including the timezone adjustments?


回答1:


Try this one :

DATEDIFF("SECOND",(DT_DBTIMESTAMP)"01/01/1970",GETDATE())


来源:https://stackoverflow.com/questions/32752706/ssis-expression-builder-convert-date-time-to-epoch-timestamp

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