On a table I have a bigint column that stores a timestamp with a microsecond precision like:
636453251396217655
636453251398405201
636453251592389899
636453251668326820
I have to build a script that, if that date is older than a week, the row must moved to another table.
I tried to convert to date using:
CREATE FUNCTION [dbo].[UNIXToDateTime] (@timestamp bigint)
RETURNS datetime
AS
BEGIN
DECLARE @ret datetime
SELECT @ret = DATEADD(second, @timestamp, '1970/01/01 00:00:00')
RETURN @ret
END
and used like:
select dbo.UNIXToDateTime(636453251396217655)
but because of the bigint my script crash because:
Arithmetic overflow error during expression conversion in int data type
I can lose precision, the important is the date part that is the main part of the sql filter.