码迷,mamicode.com
首页 > 其他好文 > 详细

日期时间函数

时间:2016-06-27 10:33:41      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2016-06-26 18:39:55 |
+---------------------+
1 row in set (0.17 sec)

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2016-06-26 |
+------------+
1 row in set (0.00 sec)

mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 18:40:14  |
+-----------+
1 row in set (0.00 sec)

mysql> select extract(day from "2012-4-5");
+------------------------------+
| extract(day from "2012-4-5") |
+------------------------------+
|                            5 |
+------------------------------+
1 row in set (0.18 sec)

mysql> select extract(year from "2012-4-5");   
+-------------------------------+
| extract(year from "2012-4-5") |
+-------------------------------+
|                          2012 |
+-------------------------------+
1 row in set (0.00 sec)

mysql> select extract(month from "2012-4-5");     
+--------------------------------+
| extract(month from "2012-4-5") |
+--------------------------------+
|                              4 |
+--------------------------------+
1 row in set (0.00 sec)

mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2016-06-26 18:49:15 |
+---------------------+
1 row in set (0.00 sec)




mysql> select date_add("2012-4-5",interval 1 month); +---------------------------------------+ | date_add("2012-4-5",interval 1 month) | +---------------------------------------+ | 2012-05-05 | +---------------------------------------+ 1 row in set (0.00 sec) mysql> select date_add("2012-4-5",interval 1 year); +--------------------------------------+ | date_add("2012-4-5",interval 1 year) | +--------------------------------------+ | 2013-04-05 | +--------------------------------------+ 1 row in set (0.00 sec) mysql> select date_add("2012-4-5",interval 1 day); +-------------------------------------+ | date_add("2012-4-5",interval 1 day) | +-------------------------------------+ | 2012-04-06 | +-------------------------------------+ 1 row in set (0.00 sec) mysql> select date_add("2012-4-5",interval 1 minute); +----------------------------------------+ | date_add("2012-4-5",interval 1 minute) | +----------------------------------------+ | 2012-04-05 00:01:00 | +----------------------------------------+ 1 row in set (0.00 sec) mysql> select date_add("2012-4-5",interval 1 hour); +--------------------------------------+ | date_add("2012-4-5",interval 1 hour) | +--------------------------------------+ | 2012-04-05 01:00:00 | +--------------------------------------+ 1 row in set (0.00 sec)

mysql> select date_add("2012-4-5",interval 1 second);
+----------------------------------------+
| date_add("2012-4-5",interval 1 second) |
+----------------------------------------+
| 2012-04-05 00:00:01 |
+----------------------------------------+
1 row in set (0.00 sec)

 


mysql> select datediff("2010-7-21","2010-7-28");
+-----------------------------------+
| datediff("2010-7-21","2010-7-28") |
+-----------------------------------+
|                                -7 |
+-----------------------------------+
1 row in set (0.01 sec)

 

日期时间函数

标签:

原文地址:http://www.cnblogs.com/zengkefu/p/5619277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!