为什么不把这个CDATE格式改为mm / yyyy?

我想将string“mm / dd / yy hh:mm AM / PM”转换为date“mm / yyyy”

为什么下面的代码输出11-2-2015

 Sub Test() Dim yourStringDate As String Dim yourDateVariable As Date yourStringDate = "11/2/15 12:00 AM" yourDateVariable = Format(CDate(yourStringDate), "mm/yyyy") MsgBox yourDateVariable End Sub 

怎么样

 Dim yourStringDate As Date yourStringDate = DateValue("11/2/15 12:00 AM") MsgBox Format(yourStringDate, "mm/yyyy") 

或以您的原始格式

 Dim yourStringDate As String Dim yourDateVariable As Date yourStringDate = "11/2/15 12:00 AM" yourDateVariable = CDate(yourStringDate) MsgBox Format(yourDateVariable, "mm/yyyy") 

我认为小写毫米是分钟,尝试月份的MM。