如何获得当前月份? [英] How to get current month?

查看:97
本文介绍了如何获得当前月份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得当前月份.

通过以下测试,获得当前年份和日期似乎非常简单:

It seems very simple to get the current year and day, as tested with the following:

MsgBox Year(Date)
MsgBox Day(Date)
MsgBox Year(Now)
MsgBox Day(Now)

如何将当前月份显示为数字(1、2等)或全名?

How is it possible to show the current month as either a number (1, 2 etc.) or a full name?

我可以在单元格中使用TODAY()并将其转换为类似CurrentMonth = MonthName(Month(Sheet1.Range("A1")))的VBA,但是我想直接在VBA for Excel中执行此操作.

I could use TODAY() in a cell and convert that in VBA with something like CurrentMonth = MonthName(Month(Sheet1.Range("A1"))) but I would like to do this directly in VBA for Excel.

推荐答案

尝试

debug.print Format(Date, "mmm")       'Mar
debug.print Format(Date, "mmmm")      'March
debug.print Format(Date, "m")    '3
debug.print Format(Date, "mm")   '03

这篇关于如何获得当前月份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆