今天小編就為大家?guī)硪黄榻BMySQL日期加減函數(shù)的文章。小編覺得挺實(shí)用的,為此分享給大家做個參考。一起跟隨小編過來看看吧。
1. addtime()
為日期加上指定秒數(shù)
select addtime(now(),1); -- 加1秒
2. adddate()
有兩種用法,第二個參數(shù)直接填數(shù)字的話是為日期加上指定天數(shù),填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時間作為參數(shù),用法和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()
為日期減去指定秒數(shù)
select subtime(now(), 1); -- 減1秒
5. subdate()
與adddate()函數(shù)用法一致,有兩種用法,第二個參數(shù)直接填數(shù)字的話是為日期減去指定天數(shù),填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()函數(shù)用法一致,為日期減去一個時間間隔,這個只能使用interval時間作為參數(shù)
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年
關(guān)于MySQL日期加減函數(shù)就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果喜歡這篇文章,不如把它分享出去讓更多的人看到。
本文名稱:MySQL日期加減函數(shù)怎么用?-創(chuàng)新互聯(lián)
當(dāng)前地址:http://www.rwnh.cn/article12/ceeodc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、用戶體驗(yàn)、網(wǎng)站建設(shè)、商城網(wǎng)站、面包屑導(dǎo)航、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容