Advertisement
4_2005-2006 Coding Standards #150862

DateDiffEx

Input a Starting Time and an Ending Time and this function will translate it into English. For Example: DateDiffEx("02/12/2002 5:05:28 AM","02/14/2002 8:00:58 PM") Return= "2 days, 15 hours", DateDiffEx("02/14/2002 5:05:28 AM","02/14/2002 8:00:58 PM") Return= "15 hours, 55 minutes, 30 seconds". It only includes the "s" if the value does not equal 1. It eliminates the 0 values as well.

AI

Resumo por IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fonte
original-source
Public Function DateDiffEx(StartTime As Date, EndTime As Date) As String
 DateDiffEx = DateDiffExFormat(DateDiff("d", StartTime, EndTime) \ 365, "year")
 DateDiffEx = DateDiffEx & DateDiffExFormat((DateDiff("s", StartTime, EndTime) \ 86400) _
 Mod 365, "day")
 DateDiffEx = DateDiffEx & DateDiffExFormat((DateDiff("s", StartTime, EndTime) \ 3600) _
 Mod 24, "hour")
 DateDiffEx = DateDiffEx & DateDiffExFormat((DateDiff("s", StartTime, EndTime) \ 60) _
 Mod 60, "minute")
 DateDiffEx = DateDiffEx & DateDiffExFormat(DateDiff("s", StartTime, EndTime) _
 Mod 60, "second")
 
 If Len(DateDiffEx) > 0 Then
 DateDiffEx = Mid(DateDiffEx, 1, Len(DateDiffEx) - 2)
 End If
End Function
Private Function DateDiffExFormat(inputValue As Long, unitValue As String) As String
 If inputValue <> 0 Then
 DateDiffExFormat = inputValue & " " & unitValue & IIf(inputValue <> 1, "s", "") & ", "
 End If
End Function
Comentários originais (3)
Recuperado do Wayback Machine