如何将十六进制转换为 varchar(datetime)?

how to cast the hexadecimal to varchar(datetime)?(如何将十六进制转换为 varchar(datetime)?)
本文介绍了如何将十六进制转换为 varchar(datetime)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期时间导出是CAST(0x0000987C00000000 AS DateTime)"但是当我想把它恢复到日期时间时.它是一个空值.我怎样才能让它再次到日期时间.

I have the datetime exporting is "CAST(0x0000987C00000000 AS DateTime)" but when I want to get it back into datetime.It is a NULL value. how can i get it to datetime again.

推荐答案

这看起来像 SQL Server datetime 格式.这在内部存储为 2 个整数,前 4 个字节是自 1900 年 1 月 1 日以来的天数,第二个字节是自午夜以来的滴答数(每个滴答声为 1/300 秒).

That looks like the SQL Server datetime format. Internally this is stored as 2 integers with the first 4 bytes being the days since 1st jan 1900 and the 2nd being the number of ticks since midnight (each tick being 1/300 of a second).

如果你需要在 MySQL 中使用它,你可以这样做

If you need to use this in MySQL you could do

SELECT 
      CAST(
          '1900-01-01 00:00:00' + 
          INTERVAL CAST(CONV(substr(HEX(BinaryData),1,8), 16, 10)  AS SIGNED) DAY +
          INTERVAL CAST(CONV(substr(HEX(BinaryData),9,8), 16, 10)  AS SIGNED)* 10000/3 MICROSECOND
      AS DATETIME) AS converted_datetime
FROM
(
SELECT 0x0000987C00000000 AS BinaryData
UNION ALL
SELECT 0x00009E85013711EE AS BinaryData
) d

退货

converted_datetime
--------------------------
2006-11-17 00:00:00
2011-02-09 18:52:34.286667

(感谢 Ted Hopp 的解决方案拆分二进制数据)

(Thanks to Ted Hopp for the solution in splitting the binary data)

这篇关于如何将十六进制转换为 varchar(datetime)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)