将分钟数转换为hh:mm [英] Convert number of minutes to hh:mm
问题描述
我在表中有一列,将分钟数存储为名为[course_access_minutes]
的numeric(18,4)
字段.
I have a column in a table that stores the number of minutes as a numeric(18,4)
field named [course_access_minutes]
.
存储的值来自黑板数据库,如下所示:
The stored values come from a blackboard database and look like this:
0.0500
0.0667
0.3667
up to
314.0833
625.8167
如何将它们转换为时间hh:mm,我对数据库文档进行了很好的了解,我能找到的只是
How do I convert these to time hh:mm, I've had a good look at the database documentation and all I can find is
course_access_minutes数字(18,4)这是用户在此登录会话期间总共访问此课程的分钟数.
course_access_minutes numeric(18,4) This is the number of minutes that the user accesses this course in total during this login session.
我可以假设我可以从几分钟直接转换为几个小时吗?我想我会将0以下的任何值都设为0分钟.在SQL中执行此操作的最佳方法是什么?预先感谢您的帮助.
Can I assume that I can make a direct conversion from minutes into hours? I think I will take any values below 1 as 0 minutes. What is the best way to do this in SQL? Thanks in advance for your help.
推荐答案
尝试一下
SELECT CONVERT(varchar, DATEADD(s, 625.8167 * 60, 0), 108)
如果持续时间超过24小时,则可以使用
If the duration is longer than 24 hours you can use this
SELECT CONVERT(varchar, CAST(1877.4501 * 60 AS int) / 3600)
+ RIGHT(CONVERT(varchar, DATEADD(s, 1877.4501 * 60, 0), 108), 6)
这篇关于将分钟数转换为hh:mm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!