SQL 将毫秒转换为天、小时、分钟 [英] SQL Convert Milliseconds to Days, Hours, Minutes

查看:306
本文介绍了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 %.

这篇关于SQL 将毫秒转换为天、小时、分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆