SQL 将毫秒转换为天、小时、分钟
问题描述:
我需要将毫秒值 85605304.3587 转换为类似 0d 18h 21m 的值.不知道如何开始,在 SQL 中是否有类似于 C# 中的 TimeSpan 的东西?
I need convert a millisecond value, 85605304.3587 to a value like 0d 18h 21m. No idea on how to start that, is there something similar to a TimeSpan in SQL like there is in C#?
答
您可以明确地进行计算.我认为是:
You can do the calculation explicitly. I think it is:
select floor(msvalue / (1000 * 60 * 60 * 24)) as days,
floor(msvalue / (1000 * 60 * 60)) % 24 as hours,
floor(msvalue / (1000 * 60)) % 60 as minutes
注意:有些数据库使用 mod
而不是 %
.
Note: Some databases use mod
instead of %
.