External data Date from YYYYMMDD to MMDDYY

  • Thread starter Thread starter Tony Girgenti
  • Start date Start date
T

Tony Girgenti

I'm working with linked ODBC tables that have dates
stored as YYYYMMDD and want to print the dates on a
report.

I tried the different date formats, but they did not work.

How do i print a date stored that way on a report ?

Any help appreciated.

Tony
 
It must be that the dates are actually strings, not dates. You can write a
function to convert them to dates. Something like the following untested
air-code:

Function ConvertTextDate(TextDate As Variant) As Variant
' Assumes TextDate is a string in YYYYMMDD format.
' TextDate is declared as a Variant to allow Nulls to be passed
' The function is declared as a Variant to allow Nulls to be returned

If Len(TextDate & "") = 8 Then
ConvertTextDate = DateSerial(Left$(TextDate, 4), _
Mid$(TextDate, 5, 2), Right$(TextDate, 2))
Else
ConvertTextDate = Null
End If

End Function

(I've left out error checking: if it's possible that the 8 character string
may not, in fact, be a valid date, you might want to add some in)
 
Back
Top