| NULL |
+----------------+
Extracting Years, Quarters, Months, and Weeks
MySQL has a range of function for extracting numerical data from a date:
YEAR(date)
QUARTER(date)
MONTH(date)
WEEK(date[,firstday])
YEARWEEK(date[,firstday])
YEAR(date) returns the 4-digit numeric year of a given date:
mysql> SELECT YEAR('01/12/25 11:00:00');
results in the following:
+-----------------------------+
| YEAR('2001/12/25 11:00:00') |
+-----------------------------+
| 2001 |
+-----------------------------+
QUARTER(date) the range 1 to 4:
mysql> SELECT QUARTER('01/12/25 11:00:00');
results in the following:
+------------------------------+
| QUARTER('01/12/25 11:00:00') |
+------------------------------+
| 4 |
+------------------------------+
MONTH(date) returns the month in the range 1 to 12:
mysql> SELECT MONTH('01/12/25 11:00:00');
results in the following:
+----------------------------+
| MONTH('01/12/25 11:00:00') |
+----------------------------+
| 12 |
+----------------------------+
WEEK(date), parameter, returns the week of the year in the range 0 to 53:
mysql> SELECT WEEK('2001-12-26');
results in the following:
+--------------------+
| WEEK('2001-12-26') |
+--------------------+
| 52 |
+--------------------+
Without a second parameter, WEEK(date) assumes that Sunday is the first day of the week, and, at
the beginning of the year, any days before the 'first day' come in week 0. For example, WEEK('2000-
01-01') returns 0 because it was a Saturday.