Date Conversion in Access YYYYMMDD

I need to use a function or nested function to convert a string value from the format of

YEARMONTHDAY   to the true date format.

I've hit a brick wall with all the traditional Access functions I normally use.....STRVAL.....DATEVAL,   MID()   etc.

Thanks in advance for any help.
James PowellData Analyst / Online Retail DevelopmentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jack LeachProprietorCommented:
Try this:

Public Function GetDateFromYYYYMMDD(ValueIn As String) As Date

  Dim s As String

  s = Left(ValueIn, 4) & "-" & Mid(ValueIn, 5, 2) & "-" & Right(ValueIn, 2)

  GetDateFromYYYYMMDD = CDate(s)

End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Helen FeddemaCommented:
Supposing the text dates are in this format:  "20140222", then this function will take the text string as an argument, and return a Date value:
Public Function TextToDate(strTextDate As String) As Date

   Dim strDate As String
   strDate = Mid(strTextDate, 5, 2) & "/" & Right(strTextDate, 2) _
      & "/ " & Left(strTextDate, 4)
   Debug.Print strDate
   TextToDate = CDate(strDate)
End Function

Open in new window

James PowellData Analyst / Online Retail DevelopmentAuthor Commented:
awesome guys...thank you...I'm trying that...
after I create the public do I reference it, in subsequent queries I might build?  (i.e. that aren't in SQL format)
James PowellData Analyst / Online Retail DevelopmentAuthor Commented:
Never mind...figured that second question like a CHARM...thank you very much!
James PowellData Analyst / Online Retail DevelopmentAuthor Commented:
It just works!  Thank you for opening my eyes to the power of this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.