MONTH( )

This MySQL function returns the numeric value of the month (0-12) for the date provided.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

MONTH(date)

Explanation

This function returns the numeric value of the month (0-12) for the date provided. Since a date column can contain a zero value (e.g., '0000-00-00'), the function will return 0 for those situations. However, for non-zero invalid dates given, NULL is returned.

Examples

SELECT appointment AS 'Appointment',
MONTH(appointment) AS 'Month of Appointment'
FROM appointments
WHERE client_id = '8302'
AND appointment > CURRDATE( );

+-------------+----------------------+
| Appointment | Month of Appointment |
+-------------+----------------------+
| 2008-06-15  |                    6 | 
+-------------+----------------------+

This SQL statement is retrieving the month of any appointments after the current date for a particular client. There's only one appointment, and it's in June.