前一天的開始時間
date_add(str_to_date(date_format(now(), '%y-%m-%d'), '%y-%m-%d %h:%i:%s'), interval - 1 day)
前一天的結束時間
date_add(date_add(str_to_date(date_format(date_sub(now(), interval 1 day), '%y-%m-%d'), '%y-%m-%d %h:%i:%s'), interval 1 day), interval - 1 second)
今天select * from 表名 where to_days(時間字段) = to_days(now())
7天select * from 表名 where date_sub(curdate(), interval 7 day) <= date(時間字段)
本月select * from 表名 where date_format(時間字段, '%y%m' ) = date_format( curdate( ) , '%y%m' )
近30天
select * from 表名 where date_sub(curdate(), interval 30 day) <= date(時間字段)
上一月select * from 表名 where period_diff( date_format( now( ), '%y%m' ) , date_format(時間字段, '%y%m' ) ) =1
#查詢本季度資料
select * from 表名 where quarter(時間字段)=quarter(now());
#查詢上季度資料
select * from 表名 where quarter(時間字段)=quarter(date_sub(now(),interval 1 quarter));
#查詢本年資料
select * from 表名 where year(時間字段)=year(now());
#查詢上年資料
select * from 表名 where year(時間字段)=year(date_sub(now(),interval 1 year));
– 查詢當前這週的資料
select name,submittime from enterprise where yearweek(date_format(submittime,』%y-%m-%d』)) = yearweek(now());
– 查詢上週的資料
select name,submittime from enterprise where yearweek(date_format(submittime,』%y-%m-%d』)) = yearweek(now())-1;
– 查詢當前月份的資料
select name,submittime from enterprise where date_format(submittime,』%y-%m』)=date_format(now(),』%y-%m』)
– 查詢距離當前現在6個月的資料
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
-- 查詢上個月的資料
select name,submittime from enterprise where date_format(submittime,』%y-%m』)=date_format(date_sub(curdate(), interval 1 month),』%y-%m』)
select*from`user`wheredate_format(pudate,『%y%m『)=date_format(curdate(),『%y%m『) ;
select * from user where weekofyear(from_unixtime(pudate,』%y-%m-%d』)) = weekofyear(now())
select*
fromuser
wheremonth(from_unixtime(pudate,『%y-%m-%d『))=month(now())
select*
from[user]
whereyear(from_unixtime(pudate,『%y-%m-%d『))=year(now())
andmonth(from_unixtime(pudate,『%y-%m-%d『))=month(now())
select*
from[user]
-- wherepudatebetween上月最後一天
-- and下月第一天
where date(regdate) = curdate();
select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())
select date( c_instime ) ,curdate( )
from `t_score`
where 1
limit 0 , 30
mysql獲取某周,某月,某年的開始時間和結束時間
一周的開始時間和結束時間 select date format subdate 2020 04 04 23 00 01 weekday 2020 04 04 23 00 01 y m d 00 00 00 date format subdate 2020 04 04 23 00 01 weekday...
PHP獲取本週開始時間
先設定時區 date default timezone set prc 網上的寫法 總覺得這週跨年或者跨月的時候會悲劇 未驗證 echo mktime 0,0,0,date m date d date w date y 同事的寫法 當本日為週日的時候 就坑了 echo strtotime last ...
android 獲取指定月份的開始時間 結束時間
根據提供的年月日獲取該月份的第一天 description 這裡用一句話描述這個方法的作用 author gyz since 2017 1 9下午2 26 57 param date return public static string getsupportbegindayofmonth date...