Excel vba 从日期对象中获取月份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47205521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:55:11  来源:igfitidea点击:

Excel vba get month from Date object

excelvbaexcel-vba

提问by Ans

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?

但是,我想与该对象分开一个月和一天。怎么做?

回答by Vityata

Month()and Day()are the functions that you need:

Month()并且Day()是功能,您需要:

MsgBox (Month(minDate))
MsgBox (Day(minDate))

Microsoft Month Reference

Microsoft 月参考

Microsoft Day Reference

微软日参考



Another way is to use the Format function:

另一种方法是使用 Format 函数:

MsgBox Format(minDate, "m")
MsgBox Format(minDate, "d")