十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
echo date('Y-m-d',strtotime ( "last Monday -1 week" )), "\n" ;
创新互联是一家专注于成都网站建设、成都做网站与策划设计,丰宁网站建设哪家好?创新互联做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:丰宁等地区。丰宁做网站价格咨询:028-86922220
echo date('Y-m-d',strtotime ( "last Sunday" )), "\n" ;
通过这个函数获取上个周的开始和结束,然后sql查询
可以研究下这个函数strtotime 。可以满足你的需求
计算本周的,需要对今天进行判断,先计算出是星期几,然后计算出星期一是 几月几号,在算出星期天是几月几号, 然后在写到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') 下面还有一例。本月统计(MySQL)
select * from booking where month(booking_time) = month(curdate()) and year(booking_time) = year(curdate())本周统计(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));//取得一周的第几天,星期天开始0-6$dn = $w ? $w - $first : 6;//要减去的天数$st = date(\"Y-m-d\", strtotime(\"$gdate -\".$dn.\" days\"));$en = date(\"Y-m-d\", strtotime(\"$st +6 days\"));return array($st, $en);//返回开始和结束日期}$weeks=implode(\"\' and \'\", aweek(\"\", 1));mysql_query(\"select * from table??where date Between \'$weeks\'\" )
思路:先关联数据库,然后执行sql语句,最后返回结果!
需要关联上数据库
?php
//创建对象并打开连接,最后一个参数是选择的数据库名称
$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(时间字段名)";
//执行sql语句,完全面向对象的
$result = $mysqli-query($sql);
while($row = $result-fetch_array()){
echo $row[0];
}
?
执行一条sql语句
SELECT *FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) = date(时间字段名)
3.运行结果、返回结果集:
$result=mysql_query($query);
并对结果进行处理!