String Parse Question

Hello all.  I have a file name such as this:

DSDAD FR6503 111806.txt

I need to grab the date in this the 111906.  What string parse can I use?  thanks all
Who is Participating?

Improve company productivity with a Business Account.Sign Up

NightmanConnect With a Mentor CTOCommented:
If the length and format is consistent:

strTemp = "DSDAD FR6503 111806.txt"
MsgBox (DateSerial("20" & Mid(strTemp, 18, 2), Mid(strTemp, 14, 2), Mid(strTemp, 16, 2)))
sbornstein2Author Commented:
Is there a way I can first grab the text of 111806 and then check if it is a date?  I think this would be easiest and then just set that to a date variable I have.
sbornstein2Author Commented:
also the file name could be different I need to work from left to right to grab it I think.  The date will always be MMDDYY.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

You could parse it out and use the IsDate(expression) - returns a boolean - if you want.
What do you mean about the file name being different? What other permutations are there?
sbornstein2Author Commented:
well your using a mid and the beginning of that file name prior to the date can possibly be different.  I think I am going to do this which is safer.

 strFileDate = Trim(Mid(myFile, InStr(myFile, ".txt") - 6, 6))
    If Len(strFileDate) = 6 Then
        strFileDate = Left(strFileDate, 2) & "/" & Mid(strFileDate, 3, 2) & _
            "/" & Format(Right(strFileDate, 1), "00")
    End If
    'Get File Date - if invalid write to error log and skip file
    If IsDate(strFileDate) = False Then
    End If
Your's is safer, true, but that's why I asked about the format. A fixed format makes for easier (and more efficient) code. And means that a simple answer would also do ;)

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.

All Courses

From novice to tech pro — start learning today.