Function GetFormatedValue3_YYYYMM(strInputDate As String) As String
strInputDate = Trim(CStr(strInputDate))
If InStr(1, strInputDate, "在岗") + InStr(1, strInputDate, "在职") > 0 Then
GetFormatedValue3_YYYYMM = strInputDate
Exit Function
ElseIf Not (IsNumeric(Left(strInputDate, 4))) Then
GetFormatedValue3_YYYYMM = "有误:" & strInputDate
Exit Function
End If
Dim intYear, intMonth As Integer
Dim FirstFindedPos As Long
If IsDate(Left(strInputDate, 4) & "-" & Mid(strInputDate, 5, 2)) Then
intYear = Left(strInputDate, 4)
intMonth = Mid(strInputDate, 5, 2)
Else
'--- 1. 删除无需的
strInputDate = Replace(strInputDate, "份", "")
strInputDate = Replace(strInputDate, "日", "")
'--- 2. 统一分隔符 -
strInputDate = Replace(strInputDate, "-年", "-")
strInputDate = Replace(strInputDate, "-月", "-")
strInputDate = Replace(strInputDate, "年", "-")
strInputDate = Replace(strInputDate, "月", "-")
strInputDate = Replace(strInputDate, "/", "-")
strInputDate = Replace(strInputDate, ".", "-")
If InStr(1, strInputDate, "-") > 0 Then
'--- 格式 ==-> 【-】
FirstFindedPos = InStr(1, strInputDate, "-")
intYear = Left(strInputDate, InStr(1, strInputDate, "-") - 1)
If InStr(FirstFindedPos + 1, strInputDate, "-") = 0 Then
'xxxx-mm
intMonth = Mid(strInputDate, FirstFindedPos + 1, 2)
Else
intMonth = Mid(strInputDate, FirstFindedPos + 1, InStr(FirstFindedPos + 1, strInputDate, "-") - InStr(1, strInputDate, "-") - 1)
End If
End If
End If
If IsDate(intYear & "-" & intMonth) Then GetFormatedValue3_YYYYMM = "'" & Format(intYear & "-" & intMonth, "yyyy-mm")
End Function