PHP 选时间(一个月开始与结束)段查询数据

这段代码展示了在Yii2和Niushop框架中如何根据用户输入的年月获取该时间段内的数据。首先,将输入的年月格式转换为时间戳,然后计算出月初和月末的时间戳,最后使用这些时间戳在数据库查询中筛选出符合条件的数据记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP 选时间(一个月开始与结束)段查询数据

      //查询年月份数据
      //yii2
        $date = \Yii::$app->request->get('time');
        $date=str_replace("年","-",$date);
        $date=str_replace("月","",$date);            
        $month_start =strtotime($date) ;//指定年月份月初时间戳
        $BeginDate=date('Y-m-01', strtotime($date));
        $EndDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
        $month_end= strtotime("next day", strtotime($EndDate)) - 1;//指定年月份月末时间戳
        
        if($name=='充值'){
              $query = IntegralLog::find()->where(['store_id' => $this->store_id, 'user_id' => $this->user_id,'type'=>1])->andFilterWhere(['between','addtime',$month_start, $month_end]);
        }
//niushop
$total=Db::name('ns_member_account_records')->where('uid',$uid)->where('account_type',1)->where('create_time','between',[$month_start,$month_end])->count();
$date=str_replace("年","-",$date);
            	$date=str_replace("月","",$date);
		            	
		        $month_start =strtotime($date) ;//指定年月份月初时间戳
		        $BeginDate=date('Y-m-01', strtotime($date));
		        $EndDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
		        $month_end= strtotime("next day", strtotime($EndDate)) - 1;//指定年月份月末时间戳
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值