问题描述
我从Microsoft SQL Server数据库中获取以下日期/时间值:
I have the following from a Microsoft SQL Server database for date/time value:
0x00009CEF00A25634
我发现这篇文章:
哪个似乎在正确的轨道上,但使用代码我没有得到正确的日期,我的十六进制日期是不同的格式?如何将它们转换为正常日期,我使用PHP / PostgreSQL。
Which seemed to be on the right track but by using the code I didn't get the right dates, are my hex dates in a different format? How would I convert them to a normal date, I am using PHP/PostgreSQL.
推荐答案
select CAST (0x00009CEF00A25634 as datetime)
给出 2009-12-30 09:51:03.000
这是两个整数。一个用于日期部分 0x00009CEF
(十进制40175),一个用于时间部分 00A25634
(十进制10638900)。日期部分是自1900年1月1日以来的天数的有符号整数。时间部分是表示滴答数的整数。
This is two integers. One for the date part 0x00009CEF
(decimal 40175) and one for the time part 00A25634
(decimal 10638900). The date part is a signed integer giving number of days since 1 Jan 1900. The time part is an integer representing number of ticks.
一秒钟内有300个刻度。
There are 300 ticks in a second.
可以看出,以下内容也返回相同的结果
It can be seen that the following also returns the same result
SELECT DATEADD(MILLISECOND,10638900*10/3.0, DATEADD(DAY,40175, '19000101'))
您将需要找出如何将其应用于 postgres
。
You will need to figure out how to apply this to postgres
.
编辑:答案显然是这样做的。我没有自己测试。
an answer here apparently does this. I haven't tested it myself.
这篇关于Microsoft Hex日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!