MySQL日期加減函數(shù)詳解
1. addtime()
為日期加上指定秒數(shù)
select addtime(now(),1); -- 加1秒
2. adddate()
有兩種用法,第二個(gè)參數(shù)直接填數(shù)字的話是為日期加上指定天數(shù),填interval的話是為日期加上指定的interval時(shí)間
select adddate(now(),1); -- 加1天select adddate(now(), interval 1 day); -- 加1天select adddate(now(), interval 1 hour); --加1小時(shí)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()
為日期增加一個(gè)時(shí)間間隔,這個(gè)只能使用interval時(shí)間作為參數(shù),用法和adddate()一致
select date_add(now(), interval 1 day); -- 加1天select date_add(now(), interval 1 hour); -- 加1小時(shí)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()
為日期減去指定秒數(shù)
select subtime(now(), 1); -- 減1秒
5. subdate()
與adddate()函數(shù)用法一致,有兩種用法,第二個(gè)參數(shù)直接填數(shù)字的話是為日期減去指定天數(shù),填interval的話是為日期減去指定的interval時(shí)間
select subdate(now(),1); -- 減1天select subdate(now(), interval 1 day); -- 減1天select subdate(now(), interval 1 hour); --減1小時(shí)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()函數(shù)用法一致,為日期減去一個(gè)時(shí)間間隔,這個(gè)只能使用interval時(shí)間作為參數(shù)
select date_sub(now(), interval 1 day); -- 減1天select date_sub(now(), interval 1 hour); --減1小時(shí)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年
到此這篇關(guān)于MySQL日期加減函數(shù)詳解的文章就介紹到這了,更多相關(guān)MySQL日期加減函數(shù)匯總內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. mysql的like模式2. AIX環(huán)境下實(shí)現(xiàn)DB2向Windows 2000遷移3. SQL Server事務(wù)日志意外增大的處理方法4. 經(jīng)驗(yàn)分享:Informix和Oracle存儲過程的異同5. Mysql入門系列:MYSQL圖像數(shù)據(jù)的處理6. Sql Server2005學(xué)習(xí)日記(01)7. 盤點(diǎn)SqlServer 分頁方式和拉姆達(dá)表達(dá)式分頁8. mysql判斷表是否存在然后批量刪除的操作9. MySql導(dǎo)出后再導(dǎo)入數(shù)據(jù)時(shí)出錯(cuò)問題10. MySQL中binlog+dump備份還原詳細(xì)教程
