主頁 > 知識庫 > Mysql日期查詢的詳細(xì)介紹

Mysql日期查詢的詳細(xì)介紹

熱門標(biāo)簽:申請400電話電話價(jià)格 宜賓全自動外呼系統(tǒng)廠家 地圖標(biāo)注客戶付款 廣東400企業(yè)電話申請流程 咸陽防封電銷卡 石家莊400電話辦理公司 新鄉(xiāng)智能外呼系統(tǒng)好處 臨沂做地圖標(biāo)注 許昌外呼增值業(yè)務(wù)線路

查詢當(dāng)前日期

SELECT CURRENT_DATE();
SELECT CURDATE();

查詢當(dāng)前日期和時間

SELECT NOW();

查詢今天的數(shù)據(jù)

SELECT * FROM `表名` WHERE TO_DAYS(NOW()) = TO_DAYS(`字段`);
SELECT * FROM `表名` WHERE TO_DAYS(NOW()) - TO_DAYS(`字段`) = 0;

查詢昨天的數(shù)據(jù)

SELECT * FROM ``表名`` WHERE TO_DAYS(`字段`) = TO_DAYS(NOW()) -1;
SELECT * FROM ``表名`` WHERE TO_DAYS(`字段`) - TO_DAYS(NOW()) = -1;
SELECT * FROM ``表名`` WHERE TO_DAYS(NOW()) = TO_DAYS(`字段`) +1;
SELECT * FROM ``表名`` WHERE TO_DAYS(NOW()) - TO_DAYS(`字段`) = 1;

查詢最近七天的數(shù)據(jù)

SELECT * FROM `表名` WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) = DATE(`字段`);

查詢最近三十天的數(shù)據(jù)

SELECT * FROM table WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) = DATE(`字段`);

查詢本周的數(shù)據(jù)

SELECT * FROM `表名` WHERE YEARWEEK(date_format(`字段`,'%Y-%m-%d')) = YEARWEEK(CURDATE());
SELECT * FROM `表名` WHERE YEARWEEK(date_format(`字段`,'%Y-%m-%d')) - YEARWEEK(CURDATE()) = 0;
SELECT * FROM `表名` WHERE YEARWEEK(DATE_FORMAT(`字段`,'%Y-%m-%d')) = YEARWEEK(DATE_FORMAT(CURDATE(),'%Y-%m-%d'));
SELECT * FROM `表名` WHERE YEARWEEK(DATE_FORMAT(`字段`,'%Y-%m-%d')) - YEARWEEK(DATE_FORMAT(CURDATE(),'%Y-%m-%d')) = 0;

查詢上周的數(shù)據(jù)

SELECT * FROM `表名` WHERE YEARWEEK(DATE_FORMAT(`字段`,'%Y-%m-%d')) = YEARWEEK(DATE_FORMAT(CURDATE(),'%Y-%m-%d')) - 1;
SELECT * FROM `表名` WHERE YEARWEEK(DATE_FORMAT(`字段`,'%Y-%m-%d')) - YEARWEEK(DATE_FORMAT(CURDATE(),'%Y-%m-%d')) = -1;
SELECT * FROM `表名` WHERE YEARWEEK(DATE_FORMAT(`字段`,'%Y-%m-%d')) = YEARWEEK(CURDATE()) - 1;
SELECT * FROM `表名` WHERE YEARWEEK(DATE_FORMAT(`字段`,'%Y-%m-%d')) - YEARWEEK(CURDATE()) = -1;

查詢當(dāng)月的數(shù)據(jù)

SELECT * FROM `表名` WHERE DATE_FORMAT(`字段`,'%Y-%m') = DATE_FORMAT(CURDATE(),'%Y-%m');
SELECT * FROM `表名` WHERE MONTH(`字段`) - MONTH(NOW()) = 0;
SELECT * FROM `表名` WHERE MONTH(`字段`) = MONTH(NOW());

查詢上月的數(shù)據(jù)

SELECT * FROM `表名` WHERE DATE_FORMAT(`字段`,'%Y-%m') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y-%m');

查詢本季度的數(shù)據(jù)

SELECT * FROM `表名` WHERE QUARTER(`字段`) = QUARTER(NOW()) AND YEAR(`字段`) = YEAR(NOW());

查詢上季度的數(shù)據(jù)

SELECT * FROM `表名` WHERE QUARTER(`字段`) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) AND YEAR(`字段`) = YEAR(NOW());

查詢上半年(六個月)的數(shù)據(jù)

SELECT * FROM `表名` WHERE `字段` BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW();

查詢今年的數(shù)據(jù)

SELECT * FROM `表名` WHERE DATE_FORMAT(`字段`,'%Y') = DATE_FORMAT(NOW(),'%Y');
SELECT * FROM `表名` WHERE DATE_FORMAT(`字段`,'%Y') - DATE_FORMAT(NOW(),'%Y') = 0;
SELECT * FROM `表名` WHERE YEAR(NOW()) = YEAR(`字段`);
SELECT * FROM `表名` WHERE YEAR(NOW()) - YEAR(`字段`) =0;

查詢?nèi)ツ甑臄?shù)據(jù)

SELECT * FROM `表名` WHERE DATE_FORMAT(`字段`,'%Y') - DATE_FORMAT(NOW(),'%Y') = -1;
SELECT * FROM `表名` WHERE YEAR(NOW()) = YEAR(`字段`) + 1;
SELECT * FROM `表名` WHERE YEAR(NOW()) - YEAR(`字段`) = 1;

到此這篇關(guān)于Mysql之日期查詢的詳細(xì)介紹的文章就介紹到這了,更多相關(guān)Mysql之日期查詢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • mysql中格式化日期詳解
  • mysql 獲取當(dāng)前日期函數(shù)及時間格式化參數(shù)詳解
  • mysql如何查詢?nèi)掌谂c時間
  • MySQL查詢兩個日期之間記錄的方法
  • MySql日期查詢語句詳解
  • Mysql 日期格式化及復(fù)雜日期區(qū)間查詢

標(biāo)簽:日照 合肥 鎮(zhèn)江 北京 臺灣 貴州 阜新 鷹潭

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Mysql日期查詢的詳細(xì)介紹》,本文關(guān)鍵詞  Mysql,日期,查詢,的,詳細(xì),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Mysql日期查詢的詳細(xì)介紹》相關(guān)的同類信息!
  • 本頁收集關(guān)于Mysql日期查詢的詳細(xì)介紹的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章