str to date

  • Thread starter Thread starter JIM.H.
  • Start date Start date
ConvertedDate = Right("YYYYMMDD", 2) & "/" & Mid("YYYYMMDD", 5, 2) & "/" &
Left("YYYYMMDD", 4)
 
Would this work better?:

ConvertedDate = CDate(Mid("YYYYMMDD", 5, 2) & "/" & Right("YYYYMMDD", 2) &
"/" & Left("YYYYMMDD", 4))

This will give a string mm/dd/yyyy and convert it to a julian date.
I think the original had the format dd/mm/yyyy which would not be the
correct US Date.
 
The poster didn't indicate the intended use of the converted date...but if
he wants to use the converted date in a query, then he should use your
approach. Thanks.
 
Actually, I think to avoid the ambiguity of date formats,
the DateSerial function would be the best one.

Assuming the DateString is "YYYYMMDD", the expression:

ConvertedDate = DateSerial ( _
CInt(Left(DateString, 4)), _
CInt(Mid(DateString, 5, 2), _
CInt(Right(DateString, 2) )

will remove the ambiguities created by Date / Time
Regional settings.

HTH
Van T. Dinh
 
Back
Top