1、当前日期
select DATE_SUB(curdate(),INTERVAL 0 DAY) ;
2、明天日期
select DATE_SUB(curdate(),INTERVAL -1 DAY) ;
3、昨天日期
select DATE_SUB(curdate(),INTERVAL 1 DAY) ;
4、前一个小时时间
select date_sub(now(), interval 1 hour);
5、后一个小时时间
select date_sub(now(), interval -1 hour);
6、前30分钟时间
select date_add(now(),interval -30 minute)
7、后30分钟时间
select date_add(now(),interval 30 minute)
8、date_add的使用(与date_sub相比,用法以及用途基本一致,但是如果type类型是复合的话,就要用date_add了)
mysql> select date_add('2013-01-18', interval '1 2' YEAR_MONTH);
+-----------------------------------------------------+
| date_add('2013-01-18', interval '1 2' YEAR_MONTH) |
+-----------------------------------------------------+
| 2014-03-18 |
+-----------------------------------------------------+
mysql> select date_add('2013-01-18', interval '1-2' YEAR_MONTH);
+----------------------------------------------------+
| date_add('2013-01-18', interval '1-2' YEAR_MONTH) |
+----------------------------------------------------+
| 2014-03-18 |
+----------------------------------------------------+
mysql> select date_add('2013-01-18', interval '1,2' YEAR_MONTH);
+---------------------------------------------------+
| date_add('2013-01-18', interval '1,2' YEAR_MONTH) |
+---------------------------------------------------+
| 2014-03-18 |
+---------------------------------------------------+
mysql> select date_add('2013-01-18', interval 1 YEAR_MONTH);
+-----------------------------------------------+
| date_add('2013-01-18', interval 1 YEAR_MONTH) |
+-----------------------------------------------+
| 2013-02-18 |
+-----------------------------------------------+
mysql> select date_add('2013-01-18', interval -1 YEAR_MONTH);
+------------------------------------------------+
| date_add('2013-01-18', interval -1 YEAR_MONTH) |
+------------------------------------------------+
| 2012-12-18 |
+------------------------------------------------+