Convert seconds to compound duration: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 3,185: | Line 3,185: | ||
0 OK, 0:94</pre> |
0 OK, 0:94</pre> |
||
=={{header|VBA}}== |
|||
<lang vb>Private Function compound_duration(ByVal seconds As Long) As String |
|||
minutes = 60 |
|||
hours = 60 * minutes |
|||
days_ = 24 * hours |
|||
weeks = 7 * days_ |
|||
Dim out As String |
|||
w = seconds \ weeks |
|||
seconds = seconds - w * weeks |
|||
d = seconds \ days_ |
|||
seconds = seconds - d * days_ |
|||
h = seconds \ hours |
|||
seconds = seconds - h * hours |
|||
m = seconds \ minutes |
|||
s = seconds Mod minutes |
|||
out = IIf(w > 0, w & " wk, ", "") & _ |
|||
IIf(d > 0, d & " d, ", "") & _ |
|||
IIf(h > 0, h & " hr, ", "") & _ |
|||
IIf(m > 0, m & " min, ", "") & _ |
|||
IIf(s > 0, s & " sec", "") |
|||
If Right(out, 2) = ", " Then |
|||
compound_duration = Left(out, Len(out) - 2) |
|||
Else |
|||
compound_duration = out |
|||
End If |
|||
End Function |
|||
Public Sub cstcd() |
|||
Debug.Print compound_duration(7259) |
|||
Debug.Print compound_duration(86400) |
|||
Debug.Print compound_duration(6000000) |
|||
End Sub</lang>{{out}} |
|||
<pre>2 hr, 59 sec |
|||
1 d |
|||
9 wk, 6 d, 10 hr, 40 min</pre> |
|||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<lang vb> |
<lang vb> |