1. addtime() 為日期加上指定秒數
select addtime(now(),1); -- 加1秒
2. adddate() 有兩種用法,第二個參數直接填數字的話是為日期加上指定天數,填interval的話是為日期加上指定的interval時間
select adddate(now(),1); -- 加1天
select adddate(now(), interval 1 day); -- 加1天
select adddate(now(), interval 1 hour); --加1小時 select adddate(now(), interval 1 minute); -- 加1分鍾 select adddate(now(), interval 1 second); -- 加1秒 select adddate(now(), interval 1 microsecond); -- 加1毫秒 select adddate(now(), interval 1 week); -- 加1周 select adddate(now(), interval 1 month); -- 加1月 select adddate(now(), interval 1 quarter); -- 加1季 select adddate(now(), interval 1 year); -- 加1年
3. date_add() 為日期增加一個時間間隔,這個只能使用interval時間作為參數,用法和adddate()一致
select date_add(now(), interval 1 day); -- 加1天 select date_add(now(), interval 1 hour); -- 加1小時 select date_add(now(), interval 1 minute); -- 加1分鍾 select date_add(now(), interval 1 second); -- 加1秒 select date_add(now(), interval 1 microsecond); -- 加1毫秒 select date_add(now(), interval 1 week); -- 加1周 select date_add(now(), interval 1 month); -- 加1月 select date_add(now(), interval 1 quarter); -- 加1季 select date_add(now(), interval 1 year); -- 加1年
4. subtime() 為日期減去指定秒數
select subtime(now(), 1); -- 減1秒
5. subdate() 與adddate()函數用法一致,有兩種用法,第二個參數直接填數字的話是為日期減去指定天數,填interval的話是為日期減去指定的interval時間
select subdate(now(),1); -- 減1天
select subdate(now(), interval 1 day); -- 減1天 select subdate(now(), interval 1 hour); --減1小時 select subdate(now(), interval 1 minute); -- 減1分鍾 select subdate(now(), interval 1 second); -- 減1秒 select subdate(now(), interval 1 microsecond); -- 減1毫秒 select subdate(now(), interval 1 week); -- 減1周 select subdate(now(), interval 1 month); -- 減1月 select subdate(now(), interval 1 quarter); -- 減1季 select subdate(now(), interval 1 year); -- 減1年
6. date_sub() 與date_add()函數用法一致,為日期減去一個時間間隔,這個只能使用interval時間作為參數
select date_sub(now(), interval 1 day); -- 減1天 select date_sub(now(), interval 1 hour); --減1小時 select date_sub(now(), interval 1 minute); -- 減1分鍾 select date_sub(now(), interval 1 second); -- 減1秒 select date_sub(now(), interval 1 microsecond); -- 減1毫秒 select date_sub(now(), interval 1 week); -- 減1周 select date_sub(now(), interval 1 month); -- 減1月 select date_sub(now(), interval 1 quarter); -- 減1季 select date_sub(now(), interval 1 year); -- 減1年