C:\Users\Administrator>mysql -u root -p Enter password: ******** 1. mysql> select curdate(),current_date(); +------------+----------------+ | curdate() | current_date() | +------------+----------------+ | 2016-02-03 | 2016-02-03 | +------------+----------------+ 1 row in set (0.01 sec) 2. mysql> select curtime(),current_time(); +-----------+----------------+ | curtime() | current_time() | +-----------+----------------+ | 21:36:39 | 21:36:39 | +-----------+----------------+ 1 row in set (0.00 sec) 3. mysql> select now(),current_timestamp(),localtime(),sysdate(); +---------------------+---------------------+---------------------+---------------------+ | now() | current_timestamp() | localtime() | sysdate() | +---------------------+---------------------+---------------------+---------------------+ | 2016-02-03 21:40:50 | 2016-02-03 21:40:50 | 2016-02-03 21:40:50 | 2016-02-03 21:40:50 | +---------------------+---------------------+---------------------+---------------------+ 1 row in set (0.00 sec) 4. mysql> select datediff('2015.08.20','2016.02.03'); +-------------------------------------+ | datediff('2015.08.20','2016.02.03') | +-------------------------------------+ | -167 | +-------------------------------------+ 1 row in set (0.02 sec) 5. mysql> select adddate('2016.02.03','10'); +----------------------------+ | adddate('2016.02.03','10') | +----------------------------+ | 2016-02-13 | +----------------------------+ 1 row in set (0.03 sec) # 不过他们的格式没有严格的要求: mysql> select adddate('2016-02-03',10); +--------------------------+ | adddate('2016-02-03',10) | +--------------------------+ | 2016-02-13 | +--------------------------+ 1 row in set (0.00 sec) 6. mysql> select adddate('2016-02-03',interval '12 3' year_month); +--------------------------------------------------+ | adddate('2016-02-03',interval '12 3' year_month) | +--------------------------------------------------+ | 2028-05-03 | +--------------------------------------------------+ 1 row in set (0.00 sec) 7. mysql> select subdate('2016-02-03',10); +--------------------------+ | subdate('2016-02-03',10) | +--------------------------+ | 2016-01-24 | +--------------------------+ 1 row in set (0.00 sec) 8. mysql> select unix_timestamp(),unix_timestamp('2016.02.03'); +------------------+------------------------------+ | unix_timestamp() | unix_timestamp('2016.02.03') | +------------------+------------------------------+ | 1454509344 | 1454428800 | +------------------+------------------------------+ 1 row in set (0.00 sec) 9. mysql> select monthname(curdate()),dayname(curdate()); +----------------------+--------------------+ | monthname(curdate()) | dayname(curdate()) | +----------------------+--------------------+ | February | Wednesday | +----------------------+--------------------+ 1 row in set (0.04 sec) 10. mysql> select dayofyear(curdate()),weekofyear(curdate()),dayofmonth(curdate()); +----------------------+-----------------------+-----------------------+ | dayofyear(curdate()) | weekofyear(curdate()) | dayofmonth(curdate()) | +----------------------+-----------------------+-----------------------+ | 34 | 5 | 3 | +----------------------+-----------------------+-----------------------+ 1 row in set (0.00 sec) 11. mysql> select hour(now()),minute(now()),second(now()); +-------------+---------------+---------------+ | hour(now()) | minute(now()) | second(now()) | +-------------+---------------+---------------+ | 22 | 36 | 29 | +-------------+---------------+---------------+ 1 row in set (0.03 sec) 12. mysql> select extract(hour from now()),extract(month from now()),extract(year from now()); +--------------------------+---------------------------+--------------------------+ | extract(hour from now()) | extract(month from now()) | extract(year from now()) | +--------------------------+---------------------------+--------------------------+ | 22 | 2 | 2016 | +--------------------------+---------------------------+--------------------------+ 1 row in set (0.00 sec) 13. mysql> select time_to_sec(now()),sec_to_time('10000'); +--------------------+----------------------+ | time_to_sec(now()) | sec_to_time('10000') | +--------------------+----------------------+ | 81870 | 02:46:40 | +--------------------+----------------------+ 1 row in set (0.00 sec) 14. mysql> select date_format(curdate(),'year:%y month:%m day:%d'); +-------------------------+ | date | +-------------------------+ | year:16 month:02 day:03 | +-------------------------+ 1 row in set (0.00 sec) mysql> select date_format(now(),'%T'); +----------+ | time | +----------+ | 22:57:02 | +----------+ 1 row in set (0.00 sec) mysql> select date_format(now(),'%y.%m.%d %T'); +----------------------------------+ | date_format(now(),'%y.%m.%d %T') | +----------------------------------+ | 16.02.03 23:02:15 | +----------------------------------+ 1 row in set (0.00 sec) mysql> select time_format(now(),'date:%y-%m-%d time:%h:%m:%s'); +--------------------------------------------------+ | time_format(now(),'date:%y-%m-%d time:%h:%m:%s') | +--------------------------------------------------+ | date:00-00-00 time:11:00:33 | +--------------------------------------------------+ 1 row in set (0.00 sec)