原文出处:http://blog.csdn.net/konglongaa/article/details/51692630
取当前时间:
select current_timestamp;
输出:2016-06-16 16:12:52
select now();
输出:2016-06-16 16:12:52
取当前时间的前一分钟:
select SUBDATE(now(),interval 60 second);
输出:2016-06-16 16:11:52
取当前时间的下一分钟:
select ADDDATE(now(),interval 60 second);
输出:2016-06-16 16:13:52
通过变化上面的单位。可以取前后 分钟,小时,天的时间
取前一分钟的时间:
select SUBDATE(now(),interval 1 minute);
输出:2016-06-16 16:16:38
取前一小时的时间:
select SUBDATE(now(),interval 1 hour);
输出:2016-06-16 15:17:38
取前一天的时间:
select SUBDATE(now(),interval 1 day);
输出:2016-06-15 16:17:38
###########################
取后一分钟的时间:
select ADDDATE(now(),interval 1 minute);
输出:2016-06-16 16:17:38
取后一小时的时间:
select ADDDATE(now(),interval 1 hour);
输出:2016-06-16 17:17:38
取后一天的时间:
select ADDDATE(now(),interval 1 day);
输出:2016-06-17 16:17:38
------------------------------------
SELECT
*
from (
select
'2017-06-07 14:51:14' t from dual
union
select
'2017-06-07 14:52:17' t from dual
union
select
'2017-06-07 14:53:17' t from dual
union
select
'2017-06-07 14:53:18' t from dual
union
select
'2017-06-07 14:54:17' t from dual
) tt
where 1=1
and tt.t BETWEEN (SUBDATE('2017-06-07 14:53:17',interval 30 second)) and (ADDDATE('2017-06-07 14:53:17',interval 30 second))
;