format file names to be used as dates

isnoend2001
isnoend2001 used Ask the Experts™
on
I am trying to remove the file extensions and any letters from file names so i can use them as dates
in one call
example: call to function
function RemoveFileName(Name as  string) as string
remove here
end function
calling function
dim myDate as date
mydate = RemoveFileName("9-20-2015.rtf") or
mydate = RemoveFileName("Mo10-25-2016.rtf")


9-20-2015.rtf
9-21-2015.rtf
9-25-2015.rtf
Yr9-20-2015.rtf
Yr10-25-2016.rtf
Dy1000.rtf'time
Wk10-25-2016.rtf
Mo10-25-2016.rtf
Yr10-25-2016.rtf
Wk10-25-2016.rtf
10-22-2016.rtf
10-21-2016.rtf
11-25-2016.rtf
Yr9-20-2016.rtf
Yr10-25-2016.rtf
Dy10-25-2016.rtf
Wk3-25-2016.rtf
Mo10-25-2016.rtf
Yr5-25-2016.rtf
Wk9-25-2016.rtf
Dy0630.rtf'time
Dy0900.rtf'time
Wk10-25-2016.rtf
Yr10-25-2016.rtf
Wk10-25-2016.rtf

Open in new window

not sure if this a proper name format for a date
10-25-2016
how can this be written ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
HI,

You don't say what you want for the time

Function removeFilename(strDate As String) As Date
Select Case UCase(Left(strDate, 2))
    Case "WK", "YR", "MO"
        Res = Left(Right(strDate, Len(strDate) - 2), Len(strDate) - 6)
    Case "DY"
        Res = Left(Right(strDate, Len(strDate) - 2), Len(strDate) - 6)
        If Res Like "####" Then
            MsgBox "it's a Time"
            Exit Function
        End If
    Case Else
        Res = Left(strDate, Len(strDate) - 4)
End Select
removeFilename = Res
End Function

Open in new window

Regards

Author

Commented:
The Time sb
Dy0630.rtf would be 0630 with the Dy and .rtf removed
Top Expert 2016

Commented:
then try

Function removeFilename(strDate As String) As Date
Select Case UCase(Left(strDate, 2))
    Case "WK", "YR", "MO", "DY"
        Res = Left(Right(strDate, Len(strDate) - 2), Len(strDate) - 6)
    Case Else
        Res = Left(strDate, Len(strDate) - 4)
End Select
removeFilename = Res
End Function

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial