Not really got time to document this, but here's a quick and cheerful function I knocked up for converting between date formats...
I'm surprised VB doesn't include something like this (he said, setting himself up for the fall...)
Hope someone finds that useful...
mmilan
I'm surprised VB doesn't include something like this (he said, setting himself up for the fall...)
Code:
Public Function ConvertDate(sDate As String, Optional sNewFormat As String = "yyyymmdd", Optional ByVal sOldFormat As String = "ddmmyy")
Dim dtDate As Date
Dim iYear As Integer
Dim iMonth As Integer
Dim iDay As Integer
Dim iPos As Integer
sOldFormat = UCase(sOldFormat)
'Start working on the old date. First of all, let's dump any CCYY
sOldFormat = VBA.Replace(sOldFormat, "CCYY", "YYYY")
'Now try and grab a year.
iPos = InStr(sOldFormat, "YYYY")
If iPos > 0 Then
'Century included.
iYear = Val(Mid(sDate, iPos, 4))
Else
iPos = InStr(sOldFormat, "YY")
If iPos > 0 Then
iYear = Val(Mid(sDate, iPos, 2))
If iYear < 30 Then
iYear = iYear + 2000
Else
iYear = iYear + 1900
End If
End If
End If
iPos = InStr(sOldFormat, "MM")
If iPos > 0 Then
iMonth = Val(Mid(sDate, iPos, 2))
End If
iPos = InStr(sOldFormat, "DD")
If iPos > 0 Then
iDay = Val(Mid(sDate, iPos, 2))
End If
If (iDay > 0) And (iMonth > 0) And (iYear > 0) Then
dtDate = DateSerial(iYear, iMonth, iDay)
ConvertDate = Format(dtDate, sNewFormat)
End If
End Function
Hope someone finds that useful...
mmilan