Below is code I am working with:
Sub TestConvertDateToStringTime()
MsgBox "#02:20#" & "-> " & ConvertDateToStringTime(#2:20:00 AM#, "hh:mm")
Debug.Print "02:20" & "-> " & ConvertDateToStringTime(#2:20:00 AM#, "hh:mm")
MsgBox "#12/31/1899 9:02:00 PM#" & "-> " & ConvertDateToStringTime(#12/31/1899 9:02:00 PM#, "hh:mm")
Debug.Print "12/31/1899 9:02:00 PM" & "-> " & ConvertDateToStringTime(#12/31/1899 9:02:00 PM#, "hh:mm")
MsgBox "#1/1/1900 02:20#" & "-> " & ConvertDateToStringTime(#1/1/1900 2:20:00 AM#, "dd:hh:mm")
Debug.Print "1/1/1900 02:20" & "-> " & ConvertDateToStringTime(#1/1/1900 2:20:00 AM#, "dd:hh:mm")
MsgBox "#1/4/1900 8:59:00 AM#" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "h:nn")
Debug.Print "1/4/1900 8:59:00 AM" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "h:nn")
MsgBox "#1/4/1900 8:59:00 AM#" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "dd:hh:nn")
Debug.Print "1/4/1900 8:59:00 AM" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "dd:hh:nn")
End Sub
-
Function ConvertDateToStringTime(StringDate As Date, FormattedTime As String) As String
On Error GoTo Err_ConvertDateToStringTime
Dim newdate As Date
Dim ldays As Variant
Dim lhours As Variant
Dim lminutes As Variant
newdate = StringDate
ldays = Int(CDbl(newdate))
If Left(FormattedTime, 1) = "d" Then
FormattedTime = Mid(FormattedTime, InStr(FormattedTime, ":") + 1)
If ldays = 0 Then
ldays = Null
Else
ldays = Format(ldays, "00") & ":"
End If
ConvertDateToStringTime = ldays & Format(newdate, FormattedTime)
Else
lhours = hour(newdate)
lhours = Format(lhours + ldays * 24, "00")
lminutes = Format(minute(newdate), "00")
ConvertDateToStringTime = lhours & ":" & lminutes
End If
Exit_ConvertDateToStringTime:
Exit Function
Err_ConvertDateToStringTime:
If Err.Number = 13 Then 'type mismatch
MsgBox "Not recognized as a date. Check format"
Resume Exit_ConvertDateToStringTime
Else
MsgBox Err.Description
Resume Exit_ConvertDateToStringTime
End If
End Function
Using this in a query:
FleetTotalTAT: ConvertDateToStringTime(Sum(convertStringTimeToDate([EOMTAT])),"HH:MM")
The problem is I am adding Total Air Time of aircraft that have huge hrs on them. Some are like 76256:25. Is there any way for the code above to ignore the over flow error and keep doing the math and add it all up??
Thanks for the help!!
jw
Sub TestConvertDateToStringTime()
MsgBox "#02:20#" & "-> " & ConvertDateToStringTime(#2:20:00 AM#, "hh:mm")
Debug.Print "02:20" & "-> " & ConvertDateToStringTime(#2:20:00 AM#, "hh:mm")
MsgBox "#12/31/1899 9:02:00 PM#" & "-> " & ConvertDateToStringTime(#12/31/1899 9:02:00 PM#, "hh:mm")
Debug.Print "12/31/1899 9:02:00 PM" & "-> " & ConvertDateToStringTime(#12/31/1899 9:02:00 PM#, "hh:mm")
MsgBox "#1/1/1900 02:20#" & "-> " & ConvertDateToStringTime(#1/1/1900 2:20:00 AM#, "dd:hh:mm")
Debug.Print "1/1/1900 02:20" & "-> " & ConvertDateToStringTime(#1/1/1900 2:20:00 AM#, "dd:hh:mm")
MsgBox "#1/4/1900 8:59:00 AM#" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "h:nn")
Debug.Print "1/4/1900 8:59:00 AM" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "h:nn")
MsgBox "#1/4/1900 8:59:00 AM#" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "dd:hh:nn")
Debug.Print "1/4/1900 8:59:00 AM" & "-> " & ConvertDateToStringTime(#1/4/1900 8:59:00 AM#, "dd:hh:nn")
End Sub
-
Function ConvertDateToStringTime(StringDate As Date, FormattedTime As String) As String
On Error GoTo Err_ConvertDateToStringTime
Dim newdate As Date
Dim ldays As Variant
Dim lhours As Variant
Dim lminutes As Variant
newdate = StringDate
ldays = Int(CDbl(newdate))
If Left(FormattedTime, 1) = "d" Then
FormattedTime = Mid(FormattedTime, InStr(FormattedTime, ":") + 1)
If ldays = 0 Then
ldays = Null
Else
ldays = Format(ldays, "00") & ":"
End If
ConvertDateToStringTime = ldays & Format(newdate, FormattedTime)
Else
lhours = hour(newdate)
lhours = Format(lhours + ldays * 24, "00")
lminutes = Format(minute(newdate), "00")
ConvertDateToStringTime = lhours & ":" & lminutes
End If
Exit_ConvertDateToStringTime:
Exit Function
Err_ConvertDateToStringTime:
If Err.Number = 13 Then 'type mismatch
MsgBox "Not recognized as a date. Check format"
Resume Exit_ConvertDateToStringTime
Else
MsgBox Err.Description
Resume Exit_ConvertDateToStringTime
End If
End Function
Using this in a query:
FleetTotalTAT: ConvertDateToStringTime(Sum(convertStringTimeToDate([EOMTAT])),"HH:MM")
The problem is I am adding Total Air Time of aircraft that have huge hrs on them. Some are like 76256:25. Is there any way for the code above to ignore the over flow error and keep doing the math and add it all up??
Thanks for the help!!
jw