我对MS Access VBA DateValue
函数有一个奇怪的问题:当我向它传递值“2012年5月4日”时,它失败并出现类型不匹配错误。
我认为是由于内部日期格式,但我不知道如何在代码级别更改格式!
目前我的解决方案是:
Public Function DateToStr(Value)
Dim Parts As Variant Parts = Split(Value, " ")
Dim Month As String
Select Case Parts(1)
Case "Jan"
Month = "Gen"
Case "May"
Month = "Mag"
Case "Jun"
Month = "Giu"
Case "Jul"
Month = "Lug"
Case "Aug"
Month = "Ago"
Case "Sep"
Month = "Set"
Case "Oct"
Month = "Ott"
Case "Dec"
Month = "Dic"
Case Else
Month = Parts(1) End Select
DateToStr = CDate(Parts(0) & "/" & Month & "/" & Parts(2))
End Function
你有什么想法吗?!?
PS:我的环境是意大利语。
答案 0 :(得分:0)
日期值函数
DateValue ("May 4, 2012")
制作“2012年5月4日”......
Function DateStr(sDS As String)
'-- format input (sDS) -> dd-mmm-yyyy - ex. "04-Mag-2012" or "04 Mag 2012"
Dim sMonth As String = ""
Select Case Mid(sDS, 4, 3)
Case "Gen" : sMonth = "January"
....
....
Case "Dic" : sMonth = "December"
End Select
DateStr = sMonth & " " & Left(sDS, 2) & ", " & Right(sDS, 4)
End Function