简体   繁体   English

将秒转换为dd:hh:mm:ss(sql:query jsp)

[英]convert secs to dd:hh:mm:ss (sql:query jsp)

My simple brain is having trouble in determining which changes I need to make to this (which is working) 我的头脑很简单,无法确定我需要对此进行哪些更改(正在起作用)

SELECT Name, Zone, Duration,

FLOOR(Duration/3600) as hours

,ROUND(FLOOR((Duration/3600-FLOOR(Duration/3600))*60)) as mins

,ROUND((((Duration/3600-FLOOR(Duration/3600))*60) - FLOOR((Duration/3600-FLOOR(Duration/3600))*60)) * 60) as secs

from duration 

(Duration is in seconds) (持续时间以秒为单位)

to determining dd:hh:mm:ss (days:hours:minutes:seconds). 确定dd:hh:mm:ss(天:小时:分钟:分钟:秒)。 I know the days calculation needs to divide by 86400 but am not sure what the other calculations should then be. 我知道天数计算需要除以86400,但不确定其他计算结果应该是多少。

Assistance appreciated. 协助表示赞赏。

Note, after many days of fiddling, this is the closest I can get to something meaningful (without any errors, NULLS etc) 请注意,经过几天的摆弄,这是我所能找到的最有意义的东西(没有任何错误,NULL等)。

SELECT Name, Zone, Duration,
FLOOR(Duration/60/60/24) as days
,FLOOR(Duration/60/60)%24 as hours
,FLOOR(Duration/60)%60 as mins
,Duration%60 as secs
from duration 

but it would be nice to display everything as 2 characters (dd:mm:hh:mm, not d:hh:m:ss etc) but not by having to use c:set, fmt then c:out etc (which is messy and long in my opinion) 但最好将所有内容显示为2个字符(dd:mm:hh:mm,而不是d:hh:m:ss等),但不必通过使用c:set,fmt然后c:out等(这很麻烦)而且我认为很长)

Regards Ralph 问候拉尔夫

Try this: 尝试这个:

SELECT Duration DIV 86400, SEC_TO_TIME(Duration MOD 86400)

To get the whole thing in one text string, do this: 要将整个内容包含在一个文本字符串中,请执行以下操作:

SELECT CONCAT_WS(':', Duration DIV 86400, SEC_TO_TIME(Duration MOD 86400))

DIV and MOD are integer operators. DIVMOD是整数运算符。 CONCAT_WS() concatenates with a specified separator character, : in your case. CONCAT_WS()与指定的分隔符:串联。

If for some reason CONCAT_WS() doesn't work, try 如果由于某种原因CONCAT_WS()无法正常工作,请尝试

SELECT CONCAT(Duration DIV 86400, ':',SEC_TO_TIME(Duration MOD 86400))

It's possible your Duration value has a datatype other than INT . 您的Duration值可能具有INT以外的数据类型。 Try this: 尝试这个:

SELECT CONCAT(CAST(Duration AS INT) DIV 86400, 
              ':',
              SEC_TO_TIME(CAST(Duration AS INT)  MOD 86400));

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

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