Access SQL:如何将存储在 int 中的年份转换为日期 - 日期为 16 世纪
Access SQL: How to convert a year stored in an int to a date - dates are in 16th century
关于 SQL 服务器或 TSQL,Stack Overflow 上有一些类似的问题(如问题 1923876, or question 266924)。但是我收到了一个 ACCESS 2010 数据库,我正在尝试在 ACCESS SQL 中将给定的解决方案与 CAST 等一起使用,但到目前为止没有成功。
日期是 16 世纪,有两列:
exact_date(日期时间)和
estimated_year(整数)。
这些列应该用于使用 ORDER BY(假设月份和日期为 1 月 1 日,如果只知道或估计年份)结果。
由于 Access SQL 不支持 CAST
,请考虑 DateSerial(year, month, day)
将整数年转换为该年 1 月 1 日的 Date/Time 值。
这是从 Access Immediate window 复制的示例:
estimated_year = 1505
? DateSerial(estimated_year, 1, 1)
1/1/1505
? TypeName(DateSerial(estimated_year, 1, 1))
Date
关于 SQL 服务器或 TSQL,Stack Overflow 上有一些类似的问题(如问题 1923876, or question 266924)。但是我收到了一个 ACCESS 2010 数据库,我正在尝试在 ACCESS SQL 中将给定的解决方案与 CAST 等一起使用,但到目前为止没有成功。
日期是 16 世纪,有两列: exact_date(日期时间)和 estimated_year(整数)。
这些列应该用于使用 ORDER BY(假设月份和日期为 1 月 1 日,如果只知道或估计年份)结果。
由于 Access SQL 不支持 CAST
,请考虑 DateSerial(year, month, day)
将整数年转换为该年 1 月 1 日的 Date/Time 值。
这是从 Access Immediate window 复制的示例:
estimated_year = 1505
? DateSerial(estimated_year, 1, 1)
1/1/1505
? TypeName(DateSerial(estimated_year, 1, 1))
Date