日期:2014-05-16 浏览次数:20956 次
mysql 有一些时间函数,虽然不常用,但是有时面试时会用到。
1.把当前时间转换成时间戳
select UNIX_TIMESTAMP();
select name,birth,year(curdate())-year(birth())-(right(curdate(),5)-right(birth,5)) as age from peg oreder by name;
以上sql 输出的图像如下是:
+----------+------------+------------+------+
| name | birth | CURDATE() | age |
+----------+------------+------------+------+
| Bowser | 1989-08-31 | 2003-08-19 | 13 |
| Buffy | 1989-05-13 | 2003-08-19 | 14 |
| Chirpy | 1998-09-11 | 2003-08-19 | 4 |
| Claws | 1994-03-17 | 2003-08-19 | 9 |