MONTH()
MONTH(date)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 nonzero invalid dates given, NULL
is returned. Here is an example:
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.