mysql關於日期 MySQL關於日期的查詢sql

2021-10-18 11:16:00 字數 1662 閱讀 6021

---查詢今天的記錄

select * from wmacc.`cash_trade_record` where  to_days(create_date) = to_days(now());

select * from wmacc.`cash_trade_record` where  date_format(create_date, '%y%m%d') = date_format(curdate(), '%y%m%d');

---查詢昨天的記錄

select * from wmacc.`cash_trade_record` where  to_days(create_date) = to_days(now()) - 1;

---查詢最近7天的記錄

select * from wmacc.`cash_trade_record` where date_sub(now(), interval 7 day) <= create_date;

---查詢本週的記錄

select * from wmacc.`cash_trade_record` where yearweek(date_format(create_date,'%y%m%d')) = yearweek(now());

---查詢上週的記錄

select * from wmacc.`cash_trade_record` where yearweek(date_format(create_date,'%y%m%d')) = yearweek(now()) - 1;

---查詢本月的記錄

select * from wmacc.`cash_trade_record` where date_format(create_date, '%y%m') = date_format(curdate(), '%y%m');

---查詢上個月的記錄

select * from wmacc.`cash_trade_record` where period_diff(date_format(now(), '%y%m'),date_format(create_date, '%y%m'))=1;

select * from wmacc.`cash_trade_record` where date_format(create_date, '%y%m') = date_format(date_sub(now(), interval 1 month), '%y%m');

---查詢本季度的記錄

select * from wmacc.`cash_trade_record` where quarter(create_date) = quarter(curdate());

---查詢上季度的記錄

select * from wmacc.`cash_trade_record` where quarter(create_date) = quarter(date_sub(now(), interval 1 quarter));

---查詢本年的記錄

select * from wmacc.`cash_trade_record` where year(create_date) = year(now());

---查詢上一年的記錄

select * from wmacc.`cash_trade_record` where year(create_date)=year(date_sub(now(),interval 1 year));

mysql關於日期 關於mysql日期的一些例子

mysql中的月份計算 減少乙個月,比如 原來的subtime 2006 10 22 12 22 22 減少後變成 2006 9 22 12 22 22 update message set subtime date sub subtime,interval 1 month 增加乙個月 update...

mysql發布日期 mysql 日期

資料型別 資料型別 格式date yyyy mm dd datetime yyyy mm dd hh mm ss timestamp yyyy mm dd hh mm ss year yyyy 或 yy 具體實現的函式 1 now 返回當前的日期和時間 select now 2 curdate 返回...

mysql日期函 MySQL 日期函式

mysql 日期函式 1,mysql dayofweek 和 weekday 獲取星期 在 mysql 中,我們可以用 dayofweek 和 weekday 函式獲取指定日期的星期.區別在於 dayofweek 獲取的星期索引是以 1 開始,而 weekday 獲取的星期索引是以 0 開始.day...