mysql按照年月日取資料

2021-10-06 09:40:28 字數 749 閱讀 9716

1、查詢當天的資料

select * from 表名 where to_days(時間字段)=to_days(now());

2、查詢當周的資料

select * from 表名 where yearweek(date_format(時間字段,』%y-%m-%d』))=yearweek(now());

3、查詢當月的資料

select * from 表名 where date_format(時間字段,』%y%m』)=date_format(curdate(),』%y%m』);

4、查詢昨天的資料

select * from 表名 where to_days(now())-to_days(時間字段)=1;

5、查詢最近7天的資料

select * from 表名 where date_sub(curdate(),interval 7 day)<=date(時間字段);

6、查詢當年的資料

select * from 表名 where year(時間字段) =year(now());

7、查詢上週的資料

select * from 表名 whereyearweek(date_format(時間字段,』%y-%m-%d』))=yearweek(now())-1;

8、查詢上月的資料

select *from 表名

where period_diff(date_format(now(),』%y%m』),date_format(時間字段,』%y%m』

按照年月日星期分組

string daily to char query date,dd 自然日 string weekly to char query date,iw 自然周 string monthly to char query date,mm 自然月 string yearly to char query da...

MySQL 按照年月日周季度分組

mysql按照年月日季度分組,結合日期函式 顯示周在年中第幾周的 返回當前函式所在那個季度 參考文章 將字串時間轉為日期,但是只能到日,想轉成年月形式不行 str to date date,y m d oracle中的to date y 代表4位的年份 y 代表2為的年份 m 代表月,格式為 01 ...

java取年月日

calendar calendar calendar.getinstance calendar.settime new date string year string.valueof calendar.get calendar.year string month string.valueof cal...