Syntax:
YEAR(date)
Description:
Returns the year for date, in the range 1000 to 9999, or 0 for the "zero" date.
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");
MariaDB [test]> 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 | +---------------------+ 6 rows in set (0.02 sec) MariaDB [test]> 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 | +---------------------+ 3 rows in set (0.09 sec)
MariaDB [(none)]> SELECT YEAR('1987-01-01'); +--------------------+ | YEAR('1987-01-01') | +--------------------+ | 1987 | +--------------------+ 1 row in set (0.00 sec) MariaDB [(none)]>
Comments
Comments loading...