echo date('Y-m-d',strtotime ( "last Monday -1 week" )), "\n" ;
創(chuàng)新互聯(lián)是一家專(zhuān)注于成都網(wǎng)站建設(shè)、成都做網(wǎng)站與策劃設(shè)計(jì),豐寧網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:豐寧等地區(qū)。豐寧做網(wǎng)站價(jià)格咨詢(xún):028-86922220
echo date('Y-m-d',strtotime ( "last Sunday" )), "\n" ;
通過(guò)這個(gè)函數(shù)獲取上個(gè)周的開(kāi)始和結(jié)束,然后sql查詢(xún)
可以研究下這個(gè)函數(shù)strtotime ??梢詽M(mǎn)足你的需求
計(jì)算本周的,需要對(duì)今天進(jìn)行判斷,先計(jì)算出是星期幾,然后計(jì)算出星期一是 幾月幾號(hào),在算出星期天是幾月幾號(hào), 然后在寫(xiě)到sql中,比如 2009-03-09到2009-03-15的話(huà),sql就是
SELECT count( ID ) AS c FROM dede_archives WHERE UNIX_TIMESTAMP( '2009-03-15') pubdate UNIX_TIMESTAMP('2009-03-09') 下面還有一例。本月統(tǒng)計(jì)(MySQL)
select * from booking where month(booking_time) = month(curdate()) and year(booking_time) = year(curdate())本周統(tǒng)計(jì)(MySQL)
select * from spf_booking where month(booking_time) = month(curdate()) and week(booking_time) = week(curdate())
function aweek($gdate = \"\", $first = 0){if(!$gdate) $gdate = date(\"Y-m-d\");$w = date(\"w\", strtotime($gdate));//取得一周的第幾天,星期天開(kāi)始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);//返回開(kāi)始和結(jié)束日期}$weeks=implode(\"\' and \'\", aweek(\"\", 1));mysql_query(\"select * from table??where date Between \'$weeks\'\" )
思路:先關(guān)聯(lián)數(shù)據(jù)庫(kù),然后執(zhí)行sql語(yǔ)句,最后返回結(jié)果!
需要關(guān)聯(lián)上數(shù)據(jù)庫(kù)
?php
//創(chuàng)建對(duì)象并打開(kāi)連接,最后一個(gè)參數(shù)是選擇的數(shù)據(jù)庫(kù)名稱(chēng)
$mysqli?=?new?mysqli('localhost','root','','volunteer');
//檢查連接是否成功
if?(mysqli_connect_errno()){
//注意mysqli_connect_error()新特性
die('Unable?to?connect!').?mysqli_connect_error();
}
$sql?=?"SELECT?*FROM?表名?where?DATE_SUB(CURDATE(),?INTERVAL?7?DAY)?=?date(時(shí)間字段名)";
//執(zhí)行sql語(yǔ)句,完全面向?qū)ο蟮?/p>
$result?=?$mysqli-query($sql);
while($row?=?$result-fetch_array()){
echo?$row[0];
}
?
執(zhí)行一條sql語(yǔ)句
SELECT?*FROM?表名?where?DATE_SUB(CURDATE(),?INTERVAL?7?DAY)?=?date(時(shí)間字段名)
3.運(yùn)行結(jié)果、返回結(jié)果集:
$result=mysql_query($query);
并對(duì)結(jié)果進(jìn)行處理!