Name
Month Function
Class
Microsoft.VisualBasic.DateAndTime
Syntax
Month(datevalue)-
datevalue Use: Required
Data Type: Date
Date variable or literal date
Return Value
An Integer between 1 and 12
Description
Returns an integer representing the month of the year of a given date expression
Rules at a Glance
If datevalue contains
Nothing, Month returns
Nothing.
Programming Tips and Gotchas
The validity of the date expression, as well as the position of the month element within the date expression, is initially determined by the locale settings of the current Windows system. However, some intelligence has been built into the
Monthfunction that surpasses the usual comparison of a date expression to the current locale settings. For example, on a Windows machine set to US date format (mm/dd/yyyy), the date “13/12/1998” would technically be illegal. However, theMonthfunction returns 12 when passed this date. The basic rule for theMonthfunction is that if the system-defined month element is outside legal bounds (i.e., greater than 12), the system-defined day element is assumed to be the month and is returned by the function.Since the
IsDatefunction adheres to the same rules and assumptions asMonth, it can be used to determine whether a date is valid before passing it to theMonthfunction.Visual Basic also has a new
MonthNamefunction for returning the name of the month.You can also use the
DatePartfunction.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access