External data Date from YYYYMMDD to MMDDYY

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
 
D

Douglas J. Steele

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top