[thelist] [OT] - mysql dbt.

Navin Dhanuka navin_dhanuka at yahoo.com
Thu Nov 22 13:51:30 CST 2001


I cannot understand why we require "-
(RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))"
and what it does.


mysql> SELECT name, birth, CURRENT_DATE,
    -> (YEAR(CURRENT_DATE)-YEAR(birth))
    -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
    -> AS age
    -> FROM pet;
+----------+------------+--------------+------+
| name     | birth      | CURRENT_DATE | age  |
+----------+------------+--------------+------+
| Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
| Claws    | 1994-03-17 | 2001-08-29   |    7 |
| Buffy    | 1989-05-13 | 2001-08-29   |   12 |
| Fang     | 1990-08-27 | 2001-08-29   |   11 |
| Bowser   | 1989-08-31 | 2001-08-29   |   11 |
| Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
| Whistler | 1997-12-09 | 2001-08-29   |    3 |
| Slim     | 1996-04-29 | 2001-08-29   |    5 |
| Puffball | 1999-03-30 | 2001-08-29   |    2 |
+----------+------------+--------------+------+




The manual says,
MySQL provides several functions that you can use to perform calculations on
dates, for example, to calculate ages or extract parts of dates.

To determine how many years old each of your pets is, compute the difference
in the year part of the current date and the birth date, then subtract one
if the current date occurs earlier in the calendar year than the birth date.
The following query shows, for each pet, the birth date, the current date,
and the age in years.



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the thelist mailing list