/** * 签到记录 */ public function getSignlog() { // 获取本周第一天的时间戳 $first_day_of_week = strtotime('this week Monday'); // 获取本周最后一天的时间戳 $last_day_of_week = strtotime('this week Sunday'); // 使用date()函数将时间戳转换为日期格式 $start_date = date('Y-m-d', $first_day_of_week); $end_date = date('Y-m-d', $last_day_of_week); $current_date = []; // 使用for循环逐个输出中间的日期 for ($i = $first_day_of_week; $i <= $last_day_of_week; $i += 86400) { $current_date[$i]['date']= date('Y-m-d', $i); $current_date[$i]['start_date']= date('Y-m-d 00:00:00', $i); $current_date[$i]['end_date']= date('Y-m-d 23:59:59', $i); } foreach ($current_date as &$value) { $connect = UserScoreLog::where(['user_id'=>$this->auth->id,'score_type'=>1]) ->where('createtime','>=',strtotime($value['start_date'])) ->where('createtime','<=',strtotime($value['end_date'])) ->field('id,continuous') ->find(); $value['signlog'] = empty($connect) ? array():$connect->toArray(); } $this->success('获取成功',$current_date); }
标签:week,strtotime,获取,日期,date,PHP,day,first From: https://www.cnblogs.com/web928943/p/17774698.html