简体   繁体   English

SQL将十六进制日期强制转换为mysql varchar(date)

[英]Sql Cast hexadecimal date to mysql varchar(date)

I have code for hexadecimal CAST(0x0000A2F5016C1769 AS DateTime) to mysql datetime, from how to cast the hexadecimal to varchar(datetime)? 我有将十六进制CAST(0x0000A2F5016C1769 AS DateTime)转换为mysql datetime的代码,从如何将十六进制转换为varchar(datetime)?

code: 码:

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 0x0000A34900BD693D AS BinaryData
    ) d

But i need to convert CAST date CAST(0xA2380B00 AS Date) to varchar date 但是我需要将CAST日期CAST(0xA2380B00 AS Date)为varchar日期

Is any possible? 有可能吗

Well, i don't really understand why you need to convert it to varchar, because if i'm not mistaken datetime behaving like string in most if not all of the situations. 好吧,我不太了解为什么需要将其转换为varchar,因为如果我没有记错日期时间,即使在大多数情况下(即使不是全部),其行为也都类似于字符串。 However, you can use the DATE_FORMAT function. 但是,您可以使用DATE_FORMAT函数。 It outputs string, and you can format the datetime if you want. 它输出字符串,并且您可以根据需要格式化日期时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM