政务桌面应用系统开发提升政府服务效率的关键所在
655
2022-11-27
按传入时间的年月周日查询
public function Summary(Request $request) { $param = $request->param(); $type = $param['type'];//按类型传入type $nian = $param['nian']; $yue = $param['yue']; $ri= $param['ri']; $type = 2; $nian = 2015; $yue = 6; $ri =8; switch ($type) { case 1: { // 时间类型日 if(empty($nian) || empty($yue) || empty($ri)){ $now = time(); $nian = date("Y",$now); $yue = date("m",$now); $ri = date("d",$now); } $time['begin'] = mktime(0,0,0,$yue,$ri,$nian); $time['end'] = mktime(23,59,59,($yue+1),$ri,$nian); }; break; case 2: { // 按周统计 if(empty($nian) || empty($yue) || empty($ri)){ $now = time(); $nian = date("Y",$now); $yue = date("m",$now); $ri = date("d",$now); } $time = $nian."/".$yue."/".$ri; $lastday= date("Y-m-d",strtotime("$time Sunday")); $time1 = strtotime(date("Y-m-d",strtotime("$lastday - 6 days"))); $time2 = strtotime($lastday); $time = array(begin =>$time1,end => $time2); }; break; case 3: { // 按月算 if(empty($nian) || empty($yue)){ $now = time(); $nian = date("Y",$now); $yue = date("m",$now); } $time['begin'] = mktime(0,0,0,$yue,1,$nian); $time['end'] = mktime(23,59,59,($yue+1),0,$nian); }; break; case 4: { // 按年统计 if(empty($nian)){ $now = time(); $nian = date("Y",$now); } $time['begin'] = mktime(0,0,0,1,1,$nian); $time['end'] = mktime(23,59,59,12,31,$nian); }; break; default: { return ''; } } var_dump($time);die;
// 接下来自己当成条件查询即可 //查询条件// $all_where = [];// $total = InvitedRecord::where('create_time', 'BETWEEN', [$start, $end])->count(); }
/** * 获取指定日期段内每一天的日期 * @param Date $startdate 开始日期 * @param Date $enddate 结束日期 * @return Array */ public function getDateFromRange($startdate, $enddate){ $stimestamp = strtotime($startdate); $etimestamp = strtotime($enddate); if ($stimestamp>$etimestamp){ $this->error('时间段结束时间不能早于开始时间',-1); } // 计算日期段内有多少天 $days = ($etimestamp-$stimestamp)/86400+1; // 保存每天日期 $date = array(); for($i=0; $i<$days; $i++){ $total[$i]['time'] = date('m/d', $stimestamp+(86400*$i)); $total[$i]['s_time'] =date('Y/m/d', $stimestamp+(86400*$i)); } return $total; } /** * 上周 * 获取指定日期段内每一天的日期 * @param Date $startdate 开始日期 * @param Date $enddate 结束日期 * @return Array */ public function getDateFromRanges($startdate, $enddate){ $stimestamp = strtotime($startdate); $etimestamp = strtotime($enddate); // 计算日期段内有多少天 $days = ($etimestamp-$stimestamp)/86400+1; $days = floor($days); // 保存每天日期 $date = array(); for($i=0; $i<$days; $i++){ $total[$i]['s_time'] =date('Y/m/d', $stimestamp+(86400*$i)); } return $total; }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~