![]() |
Converting string "061123" into a date "23/11/06"
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. |
Converting string "061123" into a date "23/11/06"
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)) WhytheQ wrote: 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. |
Converting string "061123" into a date "23/11/06"
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 WhytheQ wrote: 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. |
Converting string "061123" into a date "23/11/06"
thanks very much paul & andrew.
J On Nov 24, 9:58 am, wrote: 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 WhytheQ wrote: 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.- Hide quoted text -- Show quoted text - |
All times are GMT +1. The time now is 03:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com