YEAR
Extract the year. This function returns the year portion of a date as a number from 1000 to 9999.
Syntax
YEAR(date)Description
Returns the year for the given date, in the range 1000 to 9999, or 0 for the "zero" date.
SQL_TSI_YEAR is a synonym for YEAR:
Examples
CREATE TABLE t1 (d DATETIME);
INSERT INTO t1 VALUES
("2007-01-30 21:31:07"),
("1983-10-15 06:42:51"),
("2011-04-21 12:34:56"),
("2011-10-30 06:31:41"),
("2011-01-30 14:03:25"),
("2004-10-07 11:19:34");SELECT * FROM t1;
+---------------------+
| d |
+---------------------+
| 2007-01-30 21:31:07 |
| 1983-10-15 06:42:51 |
| 2011-04-21 12:34:56 |
| 2011-10-30 06:31:41 |
| 2011-01-30 14:03:25 |
| 2004-10-07 11:19:34 |
+---------------------+
SELECT * FROM t1 WHERE YEAR(d) = 2011;
+---------------------+
| d |
+---------------------+
| 2011-04-21 12:34:56 |
| 2011-10-30 06:31:41 |
| 2011-01-30 14:03:25 |
+---------------------+YEAR Format
The resulting output would look like this:
YEAR Range
If SQL_MODE is strict (the default), the example above generates the following error and no values are inserted:
If SQL_MODE is not strict, the example above generates a warning and (possibly modified) values are inserted:
Zero YEAR
The resulting data would look like this:
See Also
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?

