' ----------------------------------------------------------------
' Procedure Name: Convert2Date
' Purpose: Convert a 14 digit UPSWorldship string to Date with option to include Time
' Procedure Kind: Function
' Procedure Access: Public
' Parameter strUPSWorldship (String):
' Parameter withTime (Boolean): False: Date only --True: Date and Time
' Default to Date Only
' Return Type: Date
' Author: Jack
' Date: 16-Apr-21
' ----------------------------------------------------------------
Function Convert2Date(strUPSWorldship As String, Optional withTime As Boolean = False) As Date
10 Dim strUPS As String: strUPS = strUPSWorldship
Dim sYear As String
Dim sMonth As String
Dim sDay As String
Dim sHour As String
Dim sMin As String
Dim sSec As String
Dim sHold As String
20 sYear = Left(strUPS, 4)
30 sMonth = Mid(strUPS, 5, 2)
40 sDay = Mid(strUPS, 7, 2)
50 sHour = Mid(strUPS, 9, 2)
60 sMin = Mid(strUPS, 11, 2)
70 sSec = Mid(strUPS, 13, 2)
80 sHold = sYear & "/" & sMonth & "/" & sDay & " " & sHour & ":" & sMin & ":" & sSec
90 If withTime Then
100 Convert2Date = CDate(sYear & "/" & sMonth & "/" & sDay & " " & sHour & ":" & sMin & ":" & sSec)
110 Else
120 Convert2Date = CDate(sYear & "/" & sMonth & "/" & sDay)
130 End If
End Function