select curdate() as 當前日期;
select now() as 當前時間;
select date_format(curdate(),'%w') as 當前週幾;
select date_format( subdate(curdate(),date_format(curdate(),'%w')-1), '%y-%m-%d 00:00:00') as 本周一;
select date_sub(curdate(),interval weekday(curdate()) + 1 day) 本週第一天(周天);
select date_format( subdate(curdate(),date_format(curdate(),'%w')-7), '%y-%m-%d 23:59:59') as 本週末;
select date_sub(curdate(),interval weekday(curdate()) - 5 day) 本週最後一天(週六);
select date_sub(curdate(),interval weekday(curdate()) + 8 day) 上週第一天(周天);
select date_sub(curdate(),interval weekday(curdate()) + 2 day) 上週最後一天(週六);
select date_format(curdate(),'%y-%m-01 00:00:00') as 本月第一天;
select date_add(curdate(), interval - day(curdate()) + 1 day) 本月第一天;
select last_day(curdate()) 本月最後一天;
select date_add(curdate()-day(curdate())+1,interval -1 month) 上月第一天;
select last_day(date_sub(now(),interval 1 month)) 上月最後一天;
select date_add(curdate()-day(curdate())+1,interval 1 month) 下月第一天;
select last_day(date_sub(now(),interval -1 month)) 下月最後一天;
select day(last_day(curdate())) 本月天數;
select date_sub(curdate(), interval 1 month) 上月今天的當前日期;
select unix_timestamp(date_sub(now(),interval 1 month)) 上月今天的當前時間(時間戳);
select datediff(curdate(), date_sub(curdate(), interval 1 month)) 獲取當前時間與上個月之間的天數;
select * from report where create_time between date_format(curdate(),'%y-%m-01 00:00:00') and now(); -- 本月資料
select * from report where date_format(create_time, '%y%m') = date_format(curdate(), '%y%m'); -- 本月資料
select quarter(curdate()) as 當前季度;
select concat(date_format(last_day(makedate(extract(year from curdate()),1) + interval quarter(curdate())*3-3 month),'%y-%m-'),'01') as 本季度第一天;
select last_day(makedate(extract(year from curdate()),1) + interval quarter(curdate())*3-1 month) as 本季度最後一天;
select * from report where quarter(create_time)=quarter(now()); -- 本季度資料
select date_sub(curdate(), interval dayofyear(curdate())-1 day) 本年第一天;
select curdate() - interval(dayofyear(curdate()) - 1) day 本年第一天;
select concat(year(curdate()),'-12-31') 本年最後一天;
select date_sub(curdate(), interval dayofyear(curdate()) day) 上年最後一天;
select (curdate() - interval(dayofyear(curdate()) - 1) day) + interval 1 year 下年第一天;
mysql時間查詢 MySQL按時間查詢
mysql 今天select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days 時間欄位名 1 近7天select from 表名 where date sub curdate int...
mysql 時間查詢
mysql查詢今天 昨天 7天 近30天 本月 上一月 資料 推薦scofield php開發 seo sem 查詢今天 select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days...
mysql 時間查詢
select from member where datediff now mem reg time 0 查詢今天註冊的會員 select from member where datediff now mem reg time 1 查詢昨天註冊的會員 select from member where...