sql - 如何将 OLE 自动化日期值转换为 SQL Server 中的日期

标签 sql sql-server datetime double

我的应用程序将日期存储为 OLE 自动化使用 DateTime.ToOADate() 命令加倍的日期。

我需要创建一个 SQL View 来显示存储的日期。如何快速将 double 转换为日期?

最佳答案

SELECT CAST(CASE WHEN OLEFLOAT > 0 THEN 
                         OLEFLOAT-2.0 
                 ELSE 
       2*CAST(OLEFLOAT AS INT) - 2.0 +  ABS(OLEFLOAT) END as datetime)

工作?来自 here

An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

这听起来很像 SQL Server 在将日期转换为 float 时使用的相同系统,除了偏移量需要调整 2 和“负”日期。 SQL Server 将向后减去。因此 -1.25 是 18:00,而对于 OLE 则意味着 06:00。

关于sql - 如何将 OLE 自动化日期值转换为 SQL Server 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277757/

相关文章:

java - Instant 和 ZonedDateTime 之间的兼容性

Mysql 上一个日期

sql - 移动 SQL Server 数据库会降低性能

python - 如何使用 python 或 pandas 根据由字典列表组成的列来过滤 DataFrame?

sql - 如何在 SQL 中拆分数据

java - 带有基于 Hibernate 注释的 Eclipse Juno 的 HQL 编辑器

每个时间段的 MySQL 查询小计,其中小时是从当天下午 2 点到第二天下午 2 点

php - 有没有更好的方法从 MySQL 数据库获取项目?

sql - 如何从 .sql 文件创建多个存储过程

sql-server - 绝对简单的 SQL Server 查询不会返回任何内容