我有十六进制CAST代码(0x0000A2F5016C1769 AS DateTime)到mysql datetime, 来自how to cast the hexadecimal to varchar(datetime)?
代码:
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
但我需要将CAST日期CAST(0xA2380B00 AS Date)
转换为varchar日期
有可能吗?
答案 0 :(得分:0)
好吧,我真的不明白为什么你需要将它转换为varchar,因为如果我没有错误,datetime在大多数情况下表现得像字符串一样。 但是,您可以使用DATE_FORMAT功能。它输出字符串,如果需要,您可以格式化日期时间。