php每周的数据,php统计
thinkphp 怎么查本周 本月时间范围内的数据
求本周的开始和结束时间
创新互联建站专业为企业提供马鞍山网站建设、马鞍山做网站、马鞍山网站设计、马鞍山网站制作等企业网站建设、网页设计与制作、马鞍山企业网站模板建站服务,十多年马鞍山做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
$w = date('w',time()) - 1;
$start_time = time() - $w * 60 * 60 * 24; //星期一的时间戳
$end_time = time() + (6 - $w) * 60 * 60 * 24; //星期天的时间戳
M('tablename')-where("create_time = {$start_time} and create_time = $end_time")-select();
月份的也很简单了,求出本月开始和结束的时间,然后在根据时间查询就可以了
php如何获取数据库里上一周的数据?
echo date('Y-m-d',strtotime ( "last Monday -1 week" )), "\n" ;
echo date('Y-m-d',strtotime ( "last Sunday" )), "\n" ;
通过这个函数获取上个周的开始和结束,然后sql查询
可以研究下这个函数strtotime 。可以满足你的需求
php如何统计本星期的数据? - 技术问答
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\'\" )
PHP如何获取本周和本月的数据进行排行
计算本周的,需要对今天进行判断,先计算出是星期几,然后计算出星期一是 几月几号,在算出星期天是几月几号, 然后在写到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())
PHP查找一周内的数据 和一段范围的数据 怎么写SQL-CSDN论坛
/时间短查询
$starttime=GetMkTime($starttime);
$endtime=GetMkTime($endtime);
if($issettime==1){
if(!empty($starttime) !empty($endtime)){
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}else if(!empty($starttime) empty($endtime)){
$endtime=time();
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}else if(empty($starttime) !empty($endtime)){
$starttime=GetMkTime("2012-1-1");
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}
}else if($issettime==2){
if(!empty($starttime) !empty($endtime)){
$wheresql .=" AND shousu_time BETWEEN $starttime AND ".$endtime."";
}else if(!empty($starttime) empty($endtime)){
$endtime=time();
$wheresql .=" AND shousu_time BETWEEN $starttime AND ".$endtime."";
}else if(empty($starttime) !empty($endtime)){
$starttime=GetMkTime("2012-1-1");
$$wheresql .=" AND shousu_time BETWEEN $starttime AND ".$endtime."";
}
}else
{
if(!empty($starttime)){
if($isset=="jr"){
$starttime=GetDateMK($starttime);
$wheresql .=" AND datediff('".$starttime."',FROM_UNIXTIME(`paidan_time`))=0 ";
}else{
//$endtime=time();
$wheresql .=" AND paidan_time BETWEEN $starttime AND ".$endtime."";
}
/*$nowtime = time();
$passtime=$nowtime-$starttime;
$tianshu=floor($passtime/(24*60*60));
echo floor($passtime/(24*60*60)); //天数
//echo 'br/';
$starttime = $nowtime - ($tianshu*24*3600);
$wheresql .= " AND paidan_time='$starttime' ";*/
}
}
php+mysql怎么查询本周的数据
思路:先关联数据库,然后执行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);
并对结果进行处理!
文章名称:php每周的数据,php统计
URL分享:http://scyanting.com/article/hdggoo.html