| 27 | 4000 | 1979-07-10 | male | +--------+----------+---------+---------+------------+---------+ 1 row in set (0.00 sec)
可以利用英文月份来查询: mysql> select * from emp where monthname(emp_bir)="January";
查询结果显示如下: +--------+----------+---------+---------+------------+---------+ | emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex | +--------+----------+---------+---------+------------+---------+ | 100001 | 红枫 | 29 | 9000 | 1977-01-01 | male | +--------+----------+---------+---------+------------+---------+ 1 row in set (0.00 sec)
利用TO_DAYS()函数可以查询出职工们从出生到现在所经理的时间,单位是天数 mysql> select to_days(current_date) - to_days(emp_bir) as livingdays from emp;
查询后结果如下: +------------+ | livingdays | +------------+ | 9425 | | 10345 | | 9251 | +------------+ 3 rows in set (0.00 sec)
计算从现在开始经历100天后的日期 mysql> select date_add(now(),interval 100 day);
查询结果如下: +----------------------------------+ | date_add(now(),interval 100 day) | +----------------------------------+ | 2005-08-07 13:56:58 | +----------------------------------+ 1 row in set (0.00 sec)
计算从现在开始经历100天后的日期 mysql> select date_sub(now(),interval 100 day);
查询结果如下: +----------------------------------+ | date_sub(now(),interval 100 day) | +----------------------------------+ | 2005-01-19 14:00:20 | +----------------------------------+ 1 row in set (0.00 |