Return just the MM-DD component of the date with RIGHT()
mysql> mysql> mysql> CREATE TABLE sales_rep( -> employee_number INT, -> surname VARCHAR(40), -> first_name VARCHAR(30), -> commission TINYINT, -> date_joined date, -> birthday date -> ); Query OK, 0 rows affected (0.00 sec) mysql> mysql> INSERT INTO sales_rep values(1,'James','Writer',10, '1989-01-01', '1969-02-02'); Query OK, 1 row affected (0.00 sec) mysql> mysql> SELECT RIGHT(CURRENT_DATE,5),RIGHT(birthday,5) FROM sales_rep; +-----------------------+-------------------+ | RIGHT(CURRENT_DATE,5) | RIGHT(birthday,5) | +-----------------------+-------------------+ | 10-04 | 02-02 | +-----------------------+-------------------+ 1 row in set (0.00 sec) mysql> mysql> SELECT surname, first_name, (YEAR(CURRENT_DATE) - -> YEAR(birthday)) -(RIGHT(CURRENT_DATE,5)<RIGHT(birthday,5)) -> AS age FROM sales_rep; +---------+------------+------+ | surname | first_name | age | +---------+------------+------+ | James | Writer | 42 | +---------+------------+------+ 1 row in set (0.00 sec) mysql> mysql> drop table sales_rep; Query OK, 0 rows affected (0.00 sec)
1. | RIGHT( | ||
2. | SELECT RIGHT('1995-03-01',5), RIGHT('1996-02-29',5); | ||
3. | The following comparison produces a result that is correct in lexical terms but incorrect in temporal terms |