function aweek($gdate = \"\", $first = 0){if(!$gdate) $gdate = date(\"Y-m-d\");$w = date(\"w\", strtotime($gdate));//取得一周的第幾天,星期天開始0-6$dn = $w ? $w - $first : 6;//要減去的天數(shù)$st = date(\"Y-m-d\", strtotime(\"$gdate -\".$dn.\" days\"));$en = date(\"Y-m-d\", strtotime(\"$st +6 days\"));return array($st, $en);//返回開始和結(jié)束日期}$weeks=implode(\"\' and \'\", aweek(\"\", 1));mysql_query(\"select * from table??where date Between \'$weeks\'\" )
成都創(chuàng)新互聯(lián)主營東豐網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都App制作,東豐h5小程序制作搭建,東豐網(wǎng)站營銷推廣歡迎東豐等地區(qū)企業(yè)咨詢
你的數(shù)據(jù)庫里需要有一個記錄時間的字段,例如這個字段是posttime,每次插入數(shù)據(jù)的時候,都記錄下當(dāng)前的時間戳,也就是time();
你需要得到上周開始,和上周結(jié)束的時間戳
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
3.查詢的時候,WHERE 條件里加上? posttime=$beginLastweek AND posttime=$endLastweek?
希望對你有幫助
計算本周的,需要對今天進(jìn)行判斷,先計算出是星期幾,然后計算出星期一是 幾月幾號,在算出星期天是幾月幾號, 然后在寫到sql中,比如 2009-03-09到2009-03-15的話,sql就是
SELECT count( ID ) AS c FROM dede_archives WHERE UNIX_TIMESTAMP( '2009-03-15') pubdate UNIX_TIMESTAMP('2009-03-09') 下面還有一例。本月統(tǒng)計(MySQL)
select * from booking where month(booking_time) = month(curdate()) and year(booking_time) = year(curdate())本周統(tǒng)計(MySQL)
select * from spf_booking where month(booking_time) = month(curdate()) and week(booking_time) = week(curdate())