SQL 如何将数字(整数)转换为日期?
问题描述:
我正在使用小型商业软件并导入到 SQL Server.但有数字:
I'm working with small commerce software and importing to SQL Server. But there are numbers:
75739
76910
73105
75821
75245
75605
77169
73265
75611
74073
77012
代表我认为的日期.
如何将这些数字转换为日期YYYY-MM-DD
和YYYYMMDD
?
How to convert these numbers to date YYYY-MM-DD
and YYYYMMDD
?
答
基于 1900 年 1 月 1 日的 SQL Server 纪元(基准或零日期),这些日期在 22 世纪
Based on the SQL Server epoch (base or zero date) of 01 Jan 1900, these dates are in 22nd century
SELECT DATEADD(day, 75739, 0) -- 2107-05-15 00:00:00.000
还是基于日期时间的下限?这是 1960-ish,适用于出生日期
Or are they based on the lower bound of datetime? This is 1960-ish, which works for date of births
SELECT DATEADD(day, 75739, '17530101') -- 1960-05-15 00:00:00.000
tl;dr 需要更多信息.否则不要尝试
tl;dr more info needed. Otherwise don't even try