[英]Excel vba get month from Date object
I have a cell that gets filled with a date value.我有一个填充日期值的单元格。 I then store it in a variable.然后我将它存储在一个变量中。
Sub dateTest()
Dim min_date As Date
min_date = ThisWorkbook.Worksheets("setup").Cells(22, 5).value
MsgBox (min_date)
End Sub
However, I would like to get a month and a day separately from that object.但是,我想与该对象分开一个月和一天。 How to do it?怎么做?
Month()
and Day()
are the functions that you need: Month()
和Day()
是您需要的函数:
MsgBox (Month(minDate))
MsgBox (Day(minDate))
Another way is to use the Format function:另一种方法是使用 Format 函数:
MsgBox Format(minDate, "m")
MsgBox Format(minDate, "d")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.