Public Function ConvertStrDate(ByVal dt As Variant) As String
Dim datDate As String
If IsNull(dt) Then
dt = Null
ElseIf IsDate(dt) Then
datDate = Format(dt, "mmddyyyy")
ElseIf Len(dt) = 8 And Left(dt,4) In ("2008","2009","2010","2011","2012") Then '20091225 SYNTAX ERROR HERE
datDate = Format(DateSerial(Left(dt, 4), Mid(dt, 5, 2), Mid(dt, 7, 2)), "mmddyyyy")
ElseIf Len(dt) = 8 And Right(Dt,4) In ("2008","2009","2010","2011","2012") Then '12252009
datDate = Format(DateSerial(Right(dt, 4), Mid(dt, 1, 2), Mid(dt, 3, 2)), "mmddyyyy")
ElseIf Len(dt) = 5 Isdate(Cdate(dt)) = True Then 'Excel date in number format
datDate = Format(CDate(dt), "mmddyyyy")
ElseIf Len(dt) = 7 Then 'a mmddyyyy date with the leading zero omitted
dt = "0" & dt
If Left(dt,4) In ("2008","2009","2010","2011","2012") Then
datDate = Format(DateSerial(Right(dt, 4), Mid(dt, 1, 2), Mid(dt, 3, 2)), "mmddyyyy")
End If
Else
datDate = "N/A"
End If
ConvertStrDate = datDate
End Function
|