INTERVAL关键字withNOW()
和CURDATE()
MySQL函数可以以类似的方式使用,因为它可以与日期值的时间,日期或日期时间单位一起使用。
在MySQL上使用INTERVAL NOW()
mysql> Select NOW() + INTERVAL 2 day; +------------------------+ | NOW() + INTERVAL 2 day | +------------------------+ | 2017-10-30 09:19:31 | +------------------------+ 1 row in set (0.00 sec) mysql> Select NOW() - INTERVAL 2 day; +------------------------+ | NOW() - INTERVAL 2 day | +------------------------+ | 2017-10-26 09:19:45 | +------------------------+ 1 row in set (0.00 sec) mysql> Select NOW() - INTERVAL 2 hour; +-------------------------+ | NOW() - INTERVAL 2 hour | +-------------------------+ | 2017-10-28 07:19:51 | +-------------------------+ 1 row in set (0.00 sec)
在MySQL上使用INTERVAL CURDATE()
mysql> Select CURDATE() - INTERVAL 2 day; +----------------------------+ | CURDATE() - INTERVAL 2 day | +----------------------------+ | 2017-10-26 | +----------------------------+ 1 row in set (0.00 sec) mysql> Select CURDATE() + INTERVAL 2 day; +----------------------------+ | CURDATE() + INTERVAL 2 day | +----------------------------+ | 2017-10-30 | +----------------------------+ 1 row in set (0.00 sec)