Month 函数

返回一个介于 1 和 12 之间的整数(含 1 和 12),表示一年中的月份。

语法

Month(date)

参数:

Date必需。可以表示日期的任何表达式。

支持的日期格式

  • MM-DD-YYYY
  • MM/DD/YYYY
  • DD-MM-YYYY
  • DD/MM/YYYY
  • YYYY-MM-DD
  • YYYY/MM/DD

注释

以下示例使用 Month 函数返回当前月份:

示例 1

Dim MyVar
MyVar = Month(Now)
'Output: If current month is January, then it returns 1

示例 2

Dim MyDate, MyMonth
MyDate = "21/01/2025"
MyMonth = Month(MyDate)
'Output: 1 (January)

示例 3

Dim MyDate1, MyMonth1
MyDate1 = DateAdd("m", 5, "21/01/2025") 
MyMonth1 = Month(MyDate1)                 
'Output: 6 (June)

示例 4

Dim MyDateTime2, MyMonth2
MyDateTime2 = "21/01/2025 18:45:30"   ' Date-Time value.
MyMonth2 = Month(MyDateTime2)           ' Returns the month part of the date-time value.
'Output: 1 (January)