Converting Epoch time to Date Time
Posted: Mon Feb 13, 2023 3:06 pm
Hello all, I'm trying to convert an Epoch time stamp to a standard date time and add that as a Private Data Key to the job. I am using a database call to send the Epoch value and convert it using a stored procedure in SQL Server. I get the correct date returned, but I am getting an 'unknown variable' error. I've tried changing the Database Variables from Date to Text but that doesn't see to have any affect. Any help would be appreciated!
Here's my statement in Switch:
[Database.Date:SQL="EXEC [DPI_ConvertEpochTime] [Job.PrivateData:Key="EpochTime"]",Connection="Tharstern",TimeZone="UTC"]
Sample value of "EpochTime" variable:
1675749785682
Here's my SP:
ALTER PROCEDURE [dbo].[DPI_ConvertEpochTime2] @Epoch VARCHAR
AS
DECLARE @EpochNumber BIGINT = cast(@Epoch as BIGINT)
DECLARE @DateTime DATETIME
SET @DateTime = (SELECT CAST(DATEADD(ms, CAST(RIGHT(@EpochNumber,3) AS SMALLINT),
DATEADD(s, @EpochNumber / 1000, '1970-01-01')) AS DATETIME2(3)))
SELECT @DateTime
Here's my statement in Switch:
[Database.Date:SQL="EXEC [DPI_ConvertEpochTime] [Job.PrivateData:Key="EpochTime"]",Connection="Tharstern",TimeZone="UTC"]
Sample value of "EpochTime" variable:
1675749785682
Here's my SP:
ALTER PROCEDURE [dbo].[DPI_ConvertEpochTime2] @Epoch VARCHAR
AS
DECLARE @EpochNumber BIGINT = cast(@Epoch as BIGINT)
DECLARE @DateTime DATETIME
SET @DateTime = (SELECT CAST(DATEADD(ms, CAST(RIGHT(@EpochNumber,3) AS SMALLINT),
DATEADD(s, @EpochNumber / 1000, '1970-01-01')) AS DATETIME2(3)))
SELECT @DateTime