Converting string "061123" into a date "23/11/06"

  • Thread starter Thread starter WhytheQ
  • Start date Start date
W

WhytheQ

Can anybody help.
I've extracted a string from a file's name, the string is "061123"
When the macro is running I need it to convert this string into a date
formatted dd/mm/yy i.e "23/11/06"

I thought this would be relatively easy but apparently not: can anybody
help ?

Any help appreciated,
Jason.
 
Try this :

myString = "061123"

myDate = CDate(Mid(myString, 5, 2) _
& "/" & Mid(myString, 3, 2) _
& "/" & Mid(myString, 1, 2))

or
mydate = DateSerial(Mid(myString, 1, 2), Mid(myString, 3, 2),
Mid(myString, 5, 2))
 
Hi
Try

Public Sub test()
Dim myDate As String, myYear As String
Dim myMonth As String, myDay As String, myNewDate As String
myDate = "061123"
myYear = Left(myDate, 2)
myMonth = Mid(myDate, 3, 2)
myDay = Right(myDate, 2)
myNewDate = myDay & "/" & myMonth & "/" & myYear
MsgBox myNewDate
End Sub

regards
Paul
 
thanks very much paul & andrew.

J



Hi
Try

Public Sub test()
Dim myDate As String, myYear As String
Dim myMonth As String, myDay As String, myNewDate As String
myDate = "061123"
myYear = Left(myDate, 2)
myMonth = Mid(myDate, 3, 2)
myDay = Right(myDate, 2)
myNewDate = myDay & "/" & myMonth & "/" & myYear
MsgBox myNewDate
End Sub

regards
Paul
 

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

Back
Top