<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                <hr> ``` //當天時間 $where['time'] = array( array('egt',strtotime(date('Y-m-d',time()))), array('lt',strtotime(date('Y-m-d',time())).'+1 day') ); // 本周時間 $where['time'] = array( array('egt',strtotime(date('Y-m-d',time())).'-'.date('w',time()).' day'), array('lt',strtotime(date('Y-m-d',time())).'+1 week -'.date('w',time()).' day') ); // 本月時間 $where['time'] = array( array('egt',strtotime(date('Y-m',time()))), array('lt',strtotime(date('Y-m',time()).'+1 month')) ); // 本年時間 $where['time'] = array( array('egt',strtotime(date('Y',time()))), array('lt',strtotime(date('Y',time()).'+1 year')) ); //獲取近一周時間 $date7 = date('Y-m-d', strtotime('-7 days')); $date1 = date('Y-m-d', strtotime('-1 days')); $where['time'] = array( array('egt',strtotime($date7)), array('lt',strtotime($date1)) ); ``` <hr> # php+mysql統計7天、30天每天數據沒有補0 用PHP進行處理 $day為變量,這個日期我們可以定義,比如最近7天 $day為7就可以了,最近30天$day為30就可以了 ~~~php $day = 30 ;for ($i = $day - 1; 0 <= $i; $i--) {$result[] = date('m-d', strtotime('-' . $i . ' day'));$nums[] = 0;} ~~~ 這里我們構造最近30天數據,$day = 30 就會得到兩個集合 $result 日期集合 $nums 日期對應數量集合 接下來利用array_walk進行循環,沒有的補領 $scan_qushi 是我們運用最開始查詢7天的那個數據查詢方式查詢出來近30天的數據(存在沒有的) ~~~php array_walk($scan_qushi, function ($value, $key) use ($result, &$nums) {$index = array_search($value['datetime'],$result);$nums[$index] = $value['count'];});$data = ['day' => $result,'nums' => $nums]; ~~~ $result 日期 $nums 日期對應的數量,到此,我們完美的取出來了最近30天的數據。并且進行輸出。 ~~~php $data = ['day' => $result,'nums' => $nums]; ~~~ 這樣就可以交給echart工具進行數據展示了 <hr> # php+mysql獲取7天、30天的統計數據,沒有數值的補充0 ``` $order_list = db('orders') ->field('count(*) as count,date(FROM_UNIXTIME(ctime,"%Y%m%d")) as ctime,sum(total) as total') ->group("date_format(from_unixtime(ctime),'%Y%m%d')") ->where('DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime))') ->select(); //sql語句 //SELECT count(*) as count,date(FROM_UNIXTIME(ctime,"%Y%m%d")) as ctime,sum(total) as total FROM `qqxz_orders` WHERE ( DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime)) ) GROUP BY date_format(from_unixtime(ctime),'%Y%m%d') $order_list_arr = $order_list->toArray(); $day = 7; for ($i = $day - 1; 0 <= $i; $i--) { $result[] = date('Y-m-d', strtotime('-' . $i . ' day')); $nums[] = 0; $total[] = 0; } array_walk($order_list_arr, function ($value, $key) use ($result, &$nums,&$total) { $index = array_search($value['ctime'],$result); $nums[$index] = $value['count']; $total[$index] = $value['total']; }); $data = [ 'day' => $result, 'nums' => $nums, 'total' =>$total ]; halt($data); ``` <hr> php獲取未來七天的日期和星期代碼 第一步:獲取需要天數的日期,然后調用函數 //獲取未來七天的日期 for($i=1;$i<8;$i++){ $dateArray[$i]=date('Y-m-d',strtotime(date('Y-m-d').'+'.$i.'day')); }; $date = $this->get_date($dateArray);//調用函數 第二步:日期和星期函數 /* * 返回輸入日期數組對應的星期和日期 * @param $dateArray 需要的日期數組,如未來七天的日期 * */ function get_date($dateArray){ $b=array(); foreach($dateArray as $key=>$value){ $b[]=array('id'=>$key,'date'=>$value); }; foreach($b as $k=>$v){ $b[$k]['week']=$this->get_week($v['date']); $b[$k]['date']=$v['date']; } return $b; } /* * 返回輸入日期星期幾 * @param $date 日期 * */ function get_week($date){ $date_str=date('Y-m-d',strtotime($date)); $arr=explode("-", $date_str); $year=$arr[0]; $month=sprintf('%02d',$arr[1]); $day=sprintf('%02d',$arr[2]); $hour = $minute = $second = 0; $strap = mktime($hour,$minute,$second,$month,$day,$year); $number_wk=date("w",$strap); $weekArr=array("周日","周一","周二","周三","周四","周五","周六"); return $weekArr[$number_wk]; } <hr> # ThinkPHP5 (mySQL) 統計各個時間段內的訂單量 背景 今天在進行后臺數據監控時; 需要對一天24小時的下單量進行時間段的統計; 但是下單時間字段 pay_time 選取的是 timestamp 類型; 此時需要進行時間段的數據分組剝離,在此做一下實現方式,請多指教 … 環境 框架:ThinkPHP5.1.2 系統:nginx/win10 、phpStudy2017 1 2 實現方式 1. 首先,考慮到使用的是 group分組技巧; 那么就必須要將 pay_time 中記錄的字段數據進行 24時的定位切分; 這里可以用到 substring() 方法的支持 【字段取值舉例:2019-08-23 09:25:09】 2. 以我的 ThinkPHP5框架的代碼規范 源碼書寫如下: ``` $res = Db::name('order_goods og') ->field("substring(pay_time,12,2) hour,count(og.id) count") ->join("order_infos oi","oi.order_id = og.order_id") ->where([ ["pay_status","=",1]]) ->group('hour') ->order('hour','asc') ->select(); // 即對應的原生sql語句為 SELECT substring(pay_time,12,2) hour,count(og.id) count FROM tp5_xorder_goods og INNER JOIN `tp5_xorder_infos` `oi` ON `oi`.`order_id`=`og`.`order_id` WHERE `pay_status` = 1 GROUP BY `hour` ORDER BY `hour` ASC ``` ##### 3\. 之后就是對得到的數據進一步的整理 * 以我使用`ECharts圖表庫`進行數據展示為例,那么我的處理方式如下: ``` $timeRes = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; foreach ($timeRes as $key => $value){ foreach ($res as $key2 => $value2){ $hour = intval($value2['hour']); if ($key == $hour){ $timeRes[$key] = $value2['count']; //echo "hour:".$hour.";key:".$key.";count:".$value2['count']."<br/>"; break; }else{ continue; } } } ``` <hr> # php (thinkPHP)計算連續登陸天數 ``` /** * 計算當月連續登陸天數 */ $smonthtime=strtotime(date("Y-m-01")); //當月第一天 $emonthtime=strtotime("+ 1 month",$smonthtime);//當月最后一天一天 $sdaytime=strtotime(date("Y-m-d",time()));//當天開始時間 $user = M('user')->field('logintime,lastlogintime,logindays')->where("id=3")->find(); if( $user['lastlogintime'] < $sdaytime ) { //如果是當天第一次登陸 $logindays = intval($user['logindays']); if ($user['lastlogintime'] > $smonthtime && $user['lastlogintime'] < $emonthtime) { //上次登陸在本月 $datetime1 = new \DateTime(date('Y-m-d', $user['lastlogintime'])); $datetime2 = new \DateTime(date('Y-m-d', $user['logintime'])); $interval = $datetime1->diff($datetime2);//和上次登陸相差天數 $diffday = $interval->format('%d'); if ($diffday == 1) { //如果相差1天,則為連續登陸 $logindays += 1; } else { //不是連續登陸,重置連續登陸天數為1 $logindays = 1; } } else { //上次登陸時間不是在本月,重置連續登陸天數為1 $logindays = 1; } } M('user')->where("id=3")->setField("logindays",$logindays); ``` <hr> ``` date_default_timezone_set('PRC'); //默認時區 //當前的時間增加5天 $date1 = "2014-11-11"; echo date('Y-m-d',strtotime("$date1 +5 day")); //輸出結果:2014-11-16 //相應地,要增加月,年,將day改成month或year即可 //+++ 今天、昨天、明天 、上一周、下一周 +++++++++ echo "今天:",date("Y-m-d",time()),"<hr>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<hr>"; echo "明天:",date("Y-m-d",strtotime("+1 day")), "<hr>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<hr>"; echo "一周零兩天四小時兩秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<hr>"; echo "下個星期四:",date("Y-m-d",strtotime("next Thursday")), "<hr>"; echo "上個周一:".date("Y-m-d",strtotime("last Monday"))."<hr>"; echo "一個月前:".date("Y-m-d",strtotime("last month"))."<hr>"; echo "一個月后:".date("Y-m-d",strtotime("+1 month"))."<hr>"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<hr>"; ``` <hr> 本文實例講述了php獲取本周星期一具體日期的方法。分享給大家供大家參考。具體如下: ``` private function mondayTime($timestamp=0,$is_return_timestamp=true){ static $cache ; $id = $timestamp.$is_return_timestamp; if(!isset($cache[$id])){ if(!$timestamp) $timestamp = time(); $monday_date = date('Y-m-d',$timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6*86400*/518400)); if($is_return_timestamp){ $cache[$id] = strtotime($monday_date); }else{ $cache[$id] = $monday_date; } } return $cache[$id]; } echo $this->mondayTime(time() + 24*3600*2,false); exit; ``` 希望本文所述對大家的php程序設計有所幫助。 本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴 本文系統來源:php中文網 <hr> 以下是幾個獲取時間接點的方法,先獲取查詢范圍,再組織語句進行查詢。 //php獲取今日開始時間戳和結束時間戳 $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; //php獲取昨日起始時間戳和結束時間戳 $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y')); $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1; //php獲取上周起始時間戳和結束時間戳 $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')); //php獲取本月起始時間戳和結束時間戳 $beginThismonth=mktime(0,0,0,date('m'),1,date('Y')); $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y')); PHP mktime() 函數用于返回一個日期的 Unix 時間戳。 語法 mktime(hour,minute,second,month,day,year,is_dst) 參數 描述 hour 可選。規定小時。 minute 可選。規定分鐘。 second 可選。規定秒。 month 可選。規定用數字表示的月。 day 可選。規定天。 year 可選。規定年。在某些系統上,合法值介于 1901 - 2038 之間。不過在 PHP 5 中已經不存在這個限制了。 is_dst 可選。如果時間在日光節約時間(DST)期間,則設置為1,否則設置為0,若未知,則設置為-1。 使用一個between限制時間段在一個起始時間和終止時間之間,然后查詢這個時間段的數據。 $map['time'] = array('BETWEEN',array($beginThismonth,$endThismonth)); $mrecharge = $User_recharge->where($map)->sum('recharge_num'); 注意:date()中'Y-m-d H:i:s'中的H大寫代表24小時制,小寫h代表12小時制。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看