Function SecondsToText(Seconds) As String
Dim bAddComma As Boolean
Dim Result As String
Dim sTemp As String
Dim years As Double 'add code
Dim months As Double 'add code
Dim days As Double
Dim hours As Double
Dim minutes As Double
If Seconds <= 0 Or Not IsNumeric(Seconds) Then
SecondsToText = "0 seconds"
Exit Function
End If
Seconds = Fix(Seconds)
If Seconds >= 86400 Then
days = Fix(Seconds / 86400)
Else
days = 0
End If
If Seconds - (days * 86400) >= 3600 Then
hours = Fix((Seconds - (days * 86400)) / 3600)
Else
hours = 0
End If
If Seconds - (hours * 3600) - (days * 86400) >= 60 Then
minutes = Fix((Seconds - (hours * 3600) - (days * 86400)) / 60)
Else
minutes = 0
End If
Seconds = Seconds - (minutes * 60) - (hours * 3600) - _
(days * 86400)
If Seconds > 0 Then Result = Seconds & " second" & AutoS(Seconds)
If minutes > 0 Then
bAddComma = Result <> ""
sTemp = minutes & " minute" & AutoS(minutes)
If bAddComma Then sTemp = sTemp & ", "
Result = sTemp & Result
End If
If hours > 0 Then
bAddComma = Result <> ""
sTemp = hours & " hour" & AutoS(hours)
If bAddComma Then sTemp = sTemp & ", "
Result = sTemp & Result
End If
If days > 0 Then
bAddComma = Result <> ""
sTemp = days & " day" & AutoS(days)
If bAddComma Then sTemp = sTemp & ", "
Result = sTemp & Result
End If
SecondsToText = Result
End Function
Function AutoS(Number)
If Number = 1 Then AutoS = "" Else AutoS = "s"
End Function
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.