我会用下面的公式B1
:
=DATE(LEFT(A1,4),MATCH(MID(A1,6,3),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dct"},0),RIGHT(A1,2))
什么看起来很奇怪的英文缩写“DCT”为十二月。所以也许你必须根据你的语言改变数组Literal {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dct"}
。
使用VBA
以下Function
可用于:
Function convert_YYYY_MMM_DD_Text2Date(sText As String) As Variant
Dim iYear As Integer
Dim iMonth As Integer
Dim sMonth As String
Dim iDay As Integer
Dim aMonths As Variant
Dim bFound As Boolean
aMonths = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dct")
On Error GoTo errHandler
iYear = CInt(Left(sText, 4))
sMonth = Mid(sText, 6, 3)
iDay = CInt(Right(sText, 2))
For iMonth = 0 To UBound(aMonths)
If aMonths(iMonth) = sMonth Then
bFound = True
Exit For
End If
Next
If bFound Then
convert_YYYY_MMM_DD_Text2Date = DateSerial(iYear, iMonth + 1, iDay)
Else
GoTo errHandler
End If
On Error GoTo 0
Exit Function
errHandler:
convert_YYYY_MMM_DD_Text2Date = "conversion not possible"
End Function
完美的作品。有时候配方很惊人你可以用它们做什么。 – Moosli
是的,它正在工作,并感谢。但你有什么看法?什么会更快。 Tha VBA代码或这个公式在我的日期约10 000行? 我的procces看起来像: vba donwload从其他工作簿中的数据,然后将其转换为适当的colums,可以uploded到Outlook日历。 所有的代码都没有这个日期转换步骤。当然,如果我找不到最好的解决方案,我会使用像我建议的公式。 非常感谢您的支持:) –
补充了一个'VBA'函数,它接受一个字符串(“YYYY.MMM.DD”)并返回一个日期或错误字符串。 –