I'm trying to pull some data from a 3rd party SQL Database into my tables. The dates are all INT and make no sense to me FWIW the APP is based on Cobol. I was expecting "Days since Epoch" or something like that ... but it doesn't seem to map
I reckon that the Cobol datatype is an UNsigned INT and, as such, the dates run from 0 to 32,767 and then from -32,768 to -1 ... but even that isn't mapping for me.
I have a handful of INT numbers and their actual date counterparts - in case anyone can figure out the mapping please
SELECT [T_ID] = IDENTITY(int, 1, 1)
, [T_DateNo] = T1_DateNo
, [T_AbsDateNo]
, [T_Date]
, [T_DateDiff]=DATEDIFF(Day, T_Date, '19801119')
, [T_DateNoDiff] = 65536 -T_AbsDateNo
INTO #TEMP
FROM
(
SELECT [T1_DateNo]=12345, [T1_Date]='yyyymmdd' WHERE 1=0
UNION ALL SELECT 31091, '19801119'
UNION ALL SELECT 31484, '19811128'
UNION ALL SELECT 31635, '19820419'
UNION ALL SELECT 31843, '19821103'
UNION ALL SELECT 32086, '19830622'
UNION ALL SELECT -32765, '19850403'
UNION ALL SELECT -32744, '19850424'
UNION ALL SELECT -32735, '19850501'
) AS T1
CROSS APPLY
(
SELECT [T_Date]=CONVERT(date, [T1_Date])
, [T_AbsDateNo] = CASE WHEN T1_DateNo < 0 THEN 65536 + T1_DateNo
ELSE T1_DateNo
END
) AS X
ORDER BY T_Date
--
SELECT T0.T_DateNo
, T0.T_Date
, T0.T_AbsDateNo
, [AbsDiff]=T0.T_AbsDateNo-T1.T_AbsDateNo
, [DateDiff]=DATEDIFF(Day, T1.T_Date, T0.T_Date)
, [Variance] = (T0.T_AbsDateNo-T1.T_AbsDateNo) - DATEDIFF(Day, T1.T_Date, T0.T_Date)
FROM #TEMP AS T0
LEFT OUTER JOIN #TEMP AS T1
ON T1.T_ID = T0.T_ID - 1
--
ORDER BY T0.T_ID
DROP TABLE #TEMP
T_DateNo T_Date T_AbsDateNo AbsDiff DateDiff Variance
----------- ---------- ----------- ----------- ----------- -----------
31091 1980-11-19 31091 NULL NULL NULL
31484 1981-11-28 31484 393 374 19
31635 1982-04-19 31635 151 142 9
31843 1982-11-03 31843 208 198 10
32086 1983-06-22 32086 243 231 12
-32765 1985-04-03 32771 685 651 34
-32744 1985-04-24 32792 21 21 0
-32735 1985-05-01 32801 9 7 2
(8 row(s) affected)
I'll try to get some sample data that is more "decades" apart