Skip to main content
Previous section   Next section

Month

Returns the month of the year as an integer between 1 and 12, inclusive.

Synopsis

Month(date)

Arguments

The date argument is any expression that represents a date as a string.

Description

The Month function locates and returns the month portion of a date string as an integer. It performs no range validation on this number. The Month function accepts blanks, slashes (/), hyphens (-), or commas (,) (in any combination) as date component separators. Leading zeros and plus and minus signs may be included or omitted in the input string; leading zeros and signs are omitted from the output integer. The Month function locates the month portion in one of the following three ways:

  • In American numeric format, the month precedes the day. For example, “9/27/2005” or “9–27.” In this format, the Month function identifies the month portion by position. It accepts any non-numeric character as a date component separator and returns the number that precedes this first non-numeric character. It does not parse the day or year components of the date string. However, there must be at least one non-numeric character following the number specifying the month. The day and year can be any alphanumeric value, and can include or omit punctuation characters such as periods or apostrophes. The year component may be 4-digits, less than 4 digits, or omitted. If the Month function is unable to identify the month portion of the string, it returns 0.

  • In American written format, the name of the month precedes the day. For example, “September 27 2005” or “Sept 27” In this case, the month name is validated; the first three letters must correspond to a valid month name. Validation is not case-sensitive. The month name must be followed by a valid date component separator; it cannot be followed by a period; thus “Sep” or “Sept”, but not “Sept.” If the Month function is unable to identify the month portion of the string, it returns 0.

  • In European written format, the day precedes the name of the month. For example, “27 September 2005” or “27 Sept” In this case, the month name is validated; the first three letters must correspond to a valid month name. Validation is not case-sensitive. If the Month function is unable to identify the month portion of the string, it returns the day portion of the string.

Examples

The following example uses the Month function to return the current month:

Dim MonthNum
MonthNum = Month(Now)
Print MonthNum
Copy code to clipboard

The following examples uses the Month function to return the month from the specified date:

Dim MyMonth
MyMonth = Month("09/19/05")  'MyMonth contains 9.
Print MyMonth
Copy code to clipboard
Dim MyMonth
MyMonth = Month("Sept 19, 2005")  'MyMonth contains 9.
Print MyMonth
Copy code to clipboard
Dim MyMonth
MyMonth = Month("19 October 2005")  'MyMonth contains 10.
Print MyMonth
Copy code to clipboard
Dim MyMonth
MyMonth = Month("19 Feb")  'MyMonth contains 2.
Print MyMonth
Copy code to clipboard

See Also