Mysql has some time functions, although not commonly used, but sometimes used for interviews.
1. Convert the current time to the timestamp
select UNIX_TIMESTAMP();
2. We generally do not directly describe the specific age about age. Because age is constantly changing, we only need to give a birthday in the database. The SQL statement is as follows.
select name,birth,year(curdate())-year(birth())-(right(curdate(),5)-right(birth,5)) as age from peg oreder by name;
The output image of the preceding SQL statement is as follows:
+----------+------------+------------+------+
| 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 |
| Fang | 1990-08-27 | 2003-08-19 | 12 |
| Fluffy | 1993-02-04 | 2003-08-19 | 10 |
| Puffball | 1999-03-30 | 2003-08-19 | 4 |
| Slim | 1996-04-29 | 2003-08-19 | 7 |
| Whistler | 1997-12-09 | 2003-08-19 | 5 |
+----------+------------+------------+------+
3. If you want to calculate the animal born next month, the SQL statement is as follows.
Statement 1:
SELECT name, birth FROM pet WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH));
Statement 2:
select name,birth from pet where month(birth)=mod(month(curdate(),12)+1;
The reason for writing this is that in February December, if we add 1 to it, it will become 13.