MySQL Tutorial/Date Time Functions/YEAR

Материал из SQL эксперт
Перейти к: навигация, поиск

select YEAR("1973-07-20");

   <source lang="sql">

mysql> mysql> mysql> select YEAR("1989-07-20"); +--------------------+ | YEAR("1989-07-20") | +--------------------+ | 1989 | +--------------------+ 1 row in set (0.00 sec) mysql></source>


YEAR(date) returns the 4-digit numeric year of a given date:

   <source lang="sql">

mysql> mysql> SELECT YEAR("01/12/25 11:00:00"); +---------------------------+ | YEAR("01/12/25 11:00:00") | +---------------------------+ | 2001 | +---------------------------+ 1 row in set (0.00 sec) mysql></source>


YEAR(date) returns the year for date, in the range 1000 to 9999, or 0 for the "zero" date.

   <source lang="sql">

mysql> mysql> SELECT YEAR("98-02-03"); +------------------+ | YEAR("98-02-03") | +------------------+ | 1998 | +------------------+ 1 row in set (0.00 sec) mysql></source>