Name

MONTH( )

Synopsis

MONTH(date)

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

SELECT MONTH(appointment)
          AS Appointment
   FROM appointments
   WHERE client_id = '8302'
      AND appointment > CURRDATE( );
+-------------+
| Appointment |
+-------------+
|           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.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.