今天小編就為大家帶來一篇介紹MySQL日期加減函數的文章。小編覺得挺實用的,為此分享給大家做個參考。一起跟隨小編過來看看吧。

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年
關于MySQL日期加減函數就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果喜歡這篇文章,不如把它分享出去讓更多的人看到。
本文名稱:MySQL日期加減函數怎么用?-創新互聯
當前地址:http://www.yijiale78.com/article12/ceeodc.html
成都網站建設公司_創新互聯,為您提供網頁設計公司、用戶體驗、網站建設、商城網站、面包屑導航、網站改版
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯