时间日期函数

//now()  当前日期时间
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2016-10-29 13:45:31 |
+---------------------+
1 row in set (0.07 sec)


//curdate(),当前日期
mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2016-10-29 |
+------------+
1 row in set (0.05 sec)


//curtime()  当前时间
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 13:46:21  |
+-----------+
1 row in set (0.06 sec)


//date_add(); 当前日期的变化
mysql> select date_add('2016-10-29',interval 365 day);  //加365天
+-----------------------------------------+
| date_add('2016-10-29',interval 365 day) |
+-----------------------------------------+
| 2017-10-29                              |
+-----------------------------------------+
1 row in set (0.00 sec)

mysql> select date_add('2016-10-29',interval -365 day);  //减去365天
+------------------------------------------+
| date_add('2016-10-29',interval -365 day) |
+------------------------------------------+
| 2015-10-30                               |
+------------------------------------------+
1 row in set (0.35 sec)

mysql> select date_add('2016-10-29',interval 1 year);  //加上1年
+----------------------------------------+
| date_add('2016-10-29',interval 1 year) |
+----------------------------------------+
| 2017-10-29                             |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> select date_add('2016-10-29',interval 1 week);    //加上1周的时间
+----------------------------------------+
| date_add('2016-10-29',interval 1 week) |
+----------------------------------------+
| 2016-11-05                             |
+----------------------------------------+
1 row in set (0.00 sec)


//datediff();// 2个时间之间的差值
mysql> select datediff('2016-10-21','2016-10-5');
+------------------------------------+
| datediff('2016-10-21','2016-10-5') |
+------------------------------------+
|                                 16 |
+------------------------------------+
1 row in set (0.00 sec)


//date_format()   日期格式化
mysql> select date_format('2016-10-25','%m/%d/%Y');
+--------------------------------------+
| date_format('2016-10-25','%m/%d/%Y') |
+--------------------------------------+
| 10/25/2016                           |
+--------------------------------------+
1 row in set (0.00 sec)

select date_format(now(),'%Y年%m月%d日 %H点:%i分:%s秒')

posted @ 2016-10-30 14:07  Xiao|Deng  阅读(366)  评论(0编辑  收藏  举报