mysql 时间函数小结

mysql 时间函数总结

mysql 有一些时间函数,虽然不常用,但是有时面试时会用到。

1.把当前时间转换成时间戳

select  UNIX_TIMESTAMP();

2.关于年龄我们一般不直接写具体的年龄,因为年龄是不断变化的,只需要在数据库中给出生日即可。sql语句如下。

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 |
<span style="margin:0px; padding:0px; border:0px; outline:0px; vertical-align:baseline; background-color:


                        
mysql 时间函数小结

相关文章:

你感兴趣的文章:

标签云: