Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert a string Date into a formated one

Status
Not open for further replies.

sandoztek

Programmer
Aug 20, 2008
27
FR
I have the string date "23Mar08" .
Can it be easily translated into a formated one (for arithmetic operations)
 




Hi,

Spreadsheet solution...
[tt]
select the columns of dates

Data > Text to columns - STEP 3 - Column Data Format - DATE: [RED]DMY[/RED]
[/tt]
VBA Solution...
Code:
    Dim s As String
    s = "23Mar08"
    s = Left(s, Len(s) - 5) & " " & Mid(s, Len(s) - 4, 3) & " " & Right(s, 2)
    MsgBox DateValue(s)

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
If the format is fixed I would say this is even simpler
Dim s As String
s = "23Mar08"
s = Left(s, 2) & " " & Mid(s, 3, 3) & " " & Right(s, 2)
MsgBox DateValue(s)
 
Your solution is the one I finally reached too
(I used "-" instead of " ").
Thank you
 



Your solution ASSUMES, perhaps correctly, that the DAY is ALWAYS 2-digits.

BTW, this might also be informative...

faq68-5827

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Yes, my code checks the format is 2 3 2 (ddmmmyy)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top