Month 函式

傳回 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)