php mysql 读取今年到现在每个月的数据

 $month=$this->getMonth(11);
                $rmonarr=[];
                for($i=0;$i<count($month);$i++) {
                    $mon=substr($month[$i], 5);
                    if($mon == '01' || $mon == '03' || $mon =='05' || $mon == '07' || $mon =='08' || $mon=='10' ||$mon=='12'){
                        $end_time=strtotime($month[$i])+24*60*60*30-1;
                    }else{
                        $end_time= strtotime($month[$i])+24*60*60*29-1;
                    }
                    $ocount=User::where("creat_at","between time",[strtotime($month[$i]),$end_time])->count();  //可变
                    $rmonarr[$month[$i]]=$ocount;
                }
                return json(["code"=>0,"data"=>$rmonarr,'msg'=>'会员增长']);
 //获取全部月份
    private function getMonth($sign)
    {
        //得到系统的年月
        $tmp_date=date("Ym");
        //切割出年份
        $tmp_year=substr($tmp_date,0,4);
        //dump($tmp_year);
        //切割出月份
        $tmp_mon =substr($tmp_date,4,2);
        // dump($tmp_mon);
        // 得到当前月份的下几月
        $tmp_nextmonth=mktime(0,0,0,$tmp_mon+$sign,1,$tmp_year);
        // 得到当前月份的前几月
        $datearr=[];
        for($i=$sign;$i>=0;$i--)
        {
            $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-$i,1,$tmp_year);
            $datearr[]=$fm_next_month=date("Y-m",$tmp_forwardmonth);
        }

        //return $fm_next_month=date("Y-m",$tmp_forwardmonth);
        return $datearr;
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值