将mmmdd,yyyy字符串转换为日期VBA

时间:2015-04-17 11:44:58

标签: vba access-vba ms-access-2003

如何将字符串mmmdd,yyyy(Apr16,2015)转换为日期格式? Cdate和datevalue在这里不起作用 提前谢谢。

2 个答案:

答案 0 :(得分:3)

"Apr 16 2015"是可解析的:

dateStr = "Apr16,2015"
?cdate(left$(dateStr, 3) & " " & mid$(dateStr, 4, 2) & " " & right$(dateStr, 4))
16/04/2015 

答案 1 :(得分:0)

我经常使用以下方法。

dateStr = "Apr16,2015"
Yr = right(dateStr,4)
Mnth = left(dateStr,3)
Dy = mid(dateStr,4,5)
x = DateSerial(Yr,Mnth,Dy)

x = DateSerial(Year(dateStr), Month(dateStr), Day(dateStr ))