赞
踩
mysql> select current_date(),curdate();
+----------------+------------+
| current_date() | curdate() |
+----------------+------------+
| 2020-11-03 | 2020-11-03 |
+----------------+------------+
mysql> select current_time(),curtime();
+----------------+-----------+
| current_time() | curtime() |
+----------------+-----------+
| 11:11:21 | 11:11:21 |
+----------------+-----------+
mysql> select current_timestamp(),now();
+---------------------+---------------------+
| current_timestamp() | now() |
+---------------------+---------------------+
| 2020-11-03 11:11:49 | 2020-11-03 11:11:49 |
+---------------------+---------------------+
加一秒
mysql> select now(),date_add(curdate(),interval 1 second) 日期 ,date_add(curtime(),interval 1 second) 时间,date_add(now(),interval 1 second) 日期时间;
+---------------------+---------------------+----------+---------------------+
| now() | 日期 | 时间 | 日期时间 |
+---------------------+---------------------+----------+---------------------+
| 2020-11-03 11:23:50 | 2020-11-03 00:00:01 | 11:23:51 | 2020-11-03 11:23:51 |
+---------------------+---------------------+----------+---------------------+
1 row in set (0.00 sec)
加一分
mysql> select now(),date_add(curdate(),interval 1 minute) 日期 ,date_add(curtime(),interval 1 minute) 时间,date_add(now(),interval 1 minute) 日期时间;
+---------------------+---------------------+----------+---------------------+
| now() | 日期 | 时间 | 日期时间 |
+---------------------+---------------------+----------+---------------------+
| 2020-11-03 11:27:40 | 2020-11-03 00:01:00 | 11:28:40 | 2020-11-03 11:28:40 |
+---------------------+---------------------+----------+---------------------+
1 row in set (0.00 sec)
加小时
mysql> select now(),date_add(curdate(),interval 1 hour) 日期 ,date_add(curtime(),interval 1 hour) 时间,date_add(now(),interval 1 hour) 日期时间;
+---------------------+---------------------+----------+---------------------+
| now() | 日期 | 时间 | 日期时间 |
+---------------------+---------------------+----------+---------------------+
| 2020-11-03 11:28:48 | 2020-11-03 01:00:00 | 12:28:48 | 2020-11-03 12:28:48 |
加一天
mysql> select now(),date_add(curdate(),interval 1 day) 日期 ,date_add(curtime(),interval 1 day) 时间,date_add(now(),interval 1 day) 日期时间;
+---------------------+------------+----------+---------------------+
| now() | 日期 | 时间 | 日期时间 |
+---------------------+------------+----------+---------------------+
| 2020-11-03 11:30:07 | 2020-11-04 | 35:30:07 | 2020-11-04 11:30:07 |
+---------------------+------------+----------+---------------------+
1 row in set (0.00 sec)
加一月
mysql> select now(),date_add(curdate(),interval 1 month) 日期 ,date_add(curtime(),interval 1 month) 时间,date_add(now(),interval 1 month) 日期时间;
+---------------------+------------+--------+---------------------+
| now() | 日期 | 时间 | 日期时间 |
+---------------------+------------+--------+---------------------+
| 2020-11-03 11:31:03 | 2020-12-03 | NULL | 2020-12-03 11:31:03 |
+---------------------+------------+--------+---------------------+
加一年
mysql> select now(),date_add(curdate(),interval 1 year) 日期 ,date_add(curtime(),interval 1 year) 时间,date_add(now(),interval 1 year) 日期时间;
+---------------------+------------+--------+---------------------+
| now() | 日期 | 时间 | 日期时间 |
+---------------------+------------+--------+---------------------+
| 2020-11-03 11:32:33 | 2021-11-03 | NULL | 2021-11-03 11:32:33 |
+---------------------+------------+--------+---------------------+
mysql> select datediff('2000-01-02 02:02:02','2000-01-01 01:01:01');
+-------------------------------------------------------+
| datediff('2000-01-02 02:02:02','2000-01-01 01:01:01') |
+-------------------------------------------------------+
| 1 |
+-------------------------------------------------------+
将time_interval(最大到天)加到date2
mysql> select addtime('2010-01-01 01:01:01',' 01 01:01:01');
+-----------------------------------------------+
| addtime('2010-01-01 01:01:01',' 01 01:01:01') |
+-----------------------------------------------+
| 2010-01-02 02:02:02 |
+-----------------------------------------------+
mysql> select date_format(now(), '%Y-%m-%d') from dual;
+--------------------------------+
| date_format(now(), '%Y-%m-%d') |
+--------------------------------+
| 2020-11-03 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select date_format(now(), '%Y-%c-%d %h:%i:%s') from dual;
+-----------------------------------------+
| date_format(now(), '%Y-%c-%d %h:%i:%s') |
+-----------------------------------------+
| 2020-11-03 02:13:20 |
+-----------------------------------------+
1 row in set (0.00 sec)
mysql> select str_to_date('2015-2-04 05:14:15' , '%Y-%c-%d %h:%i:%s') from dual;
+---------------------------------------------------------+
| str_to_date('2015-2-04 05:14:15' , '%Y-%c-%d %h:%i:%s') |
+---------------------------------------------------------+
| 2015-02-04 05:14:15 |
+---------------------------------------------------------+
1 row in set (0.00 sec)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。