从访问表中的字符串中提取日期

时间:2018-03-11 08:06:12

标签: sql vba date ms-access

我正在尝试从访问中的以下字符串中提取date。不知道怎么做,因为所有的都是不同的格式。

AT (ALL LOCATION) (XYZ) (15TH FEB10) (some).xlsx
AT) (XYZ) (DEC-15) (bdd).xlsx
(AT SOUTH) (XYZ) (FEB11 TO MAR11) (some).xlsx
(AT) (XYZ) (APR13-DEC13) (some - sky).xlsx

1 个答案:

答案 0 :(得分:0)

此函数返回包含数字的括号之间第一次出现的字符串:

Public Function bracketedWordWithNumber(strIn As String) As String

    Dim arr() As String, x As Integer

    'test for number in parentheses
    If Not strIn Like "*(*#*)*" Then Exit Function

    'remove file extension: everything after last dot '.'
    If InStr(strIn, ".") > 0 Then strIn = Left(strIn, InStrRev(strIn, ".") - 1)

    'remove right parentheses ')'
    strIn = Replace(strIn, ")", "")

    'split into array on left parentheses '('
    arr = Split(strIn, "(")

    'iterate array
    For x = 0 To UBound(arr)
        'find strings with numbers
        If arr(x) Like "*#*" Then
            'return match
            bracketedWordWithNumber = arr(x)
            'stop after the first match
            Exit Function
        End If
    Next x

End Function

更多信息: