Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii2-如何在没有上一季度的情况下获得当前季度?_Php_Yii2 - Fatal编程技术网

Php Yii2-如何在没有上一季度的情况下获得当前季度?

Php Yii2-如何在没有上一季度的情况下获得当前季度?,php,yii2,Php,Yii2,我这里有个问题。我需要一个季度没有过去的季度。F.e.: 在我的数据库中,我在处创建了一个字段,它保存了创建的服务的时间戳。我不需要涉及那些在过去一个季度提供的服务。我该怎么做 我正在尝试编写一个类似这样的SQL函数,以避免涉及这些服务,这是在上一季度完成的: $services= Service::find() ->where([ 'client_service.created' => function ($model) {

我这里有个问题。我需要一个季度没有过去的季度。F.e.:

在我的数据库中,我在处创建了一个字段
,它保存了创建的服务的时间戳。我不需要涉及那些在过去一个季度提供的服务。我该怎么做

我正在尝试编写一个类似这样的SQL函数,以避免涉及这些服务,这是在上一季度完成的:

$services= Service::find()
        ->where([         
            'client_service.created' => function ($model) {
                 return ceil(date('n') / 3) - 4;
但我想我错了。谢谢你的帮助

编辑:

        $services= Service::find()
        ->select(['client.id as client_id'])
        ->joinWith('client')
        ->where([         
            'service.type' => Service::TYPE,
            'service.is_archived' => Service::ARCHIVED,])
        ->andWhere([
            'or',
            ['client_service.status' => ClientService::STATUS_NEGATIVE],
            [client_service.created' => function ($model) {
                 return ceil(date('n') / 3) - 4;]

查找
开始日期
结束日期
季度日期

$date =  new \DateTime(); // Current Date and Time
$quarter_start = clone($date);

// Find the offset of months
$months_offset = ($date->format('m') - 1) % 3;

// Modify quarter date
$quarter_start->modify(" - " . $months_offset . " month")->modify("first day of this month");

$quarter_end = clone($quarter_start);
$quarter_end->modify("+ 3 month");

$startDate = $quarter_start->format('Y-m-d');
$endDate = $quarter_end->format('Y-m-d');
查询

$services= Service::find()
    ->select(['client.id as client_id'])
    ->joinWith('client')
    ->where([         
        'service.type' => Service::TYPE,
        'service.is_archived' => Service::ARCHIVED,])
    ->andWhere([
        'or',
        ['client_service.status' => ClientService::STATUS_NEGATIVE],
        ['between', 'date_format(FROM_UNIXTIME(client_service.created), "%Y-%m-%d")', $startDate, $endDate]

您也可以使用mysql来实现此结果。

您将timestemp存储在db中作为服务日期,我们可以从当前月份中查找当前季度的开始日期和结束日期,并在查询中使用

     $current_month = date('m');
     $current_year = date('Y');
     if($current_month>=1 && $current_month<=3)
     {
       $start_date = strtotime($current_year.'-01-01 00:00:00');  
       $end_date = strtotime($current_year.'-03-31 23:59:59');  
     }
     else  if($current_month>=4 && $current_month<=6)
     {
       $start_date = strtotime($current_year.'-04-01 00:00:00');
       $end_date = strtotime($current_year.'-06-30 23:59:59');  
     }
     else  if($current_month>=7 && $current_month<=9)
     {
       $start_date = strtotime($current_year.'-07-01 00:00:00');
       $end_date = strtotime($current_year.'-09-30 23:59:59');
     }
     else  if($current_month>=10 && $current_month<=12)
     {
       $start_date = strtotime($current_year.'-10-01 00:00:00');
       $end_date = strtotime($current_year.'-12-31 23:59:59');
     }

你能提供完整的问题吗?我刚刚更新了这个问题
$services= Service::find()
   ->select(['client.id as client_id'])
   ->joinWith('client')
   ->where([         
       'service.type' => Service::TYPE,
       'service.is_archived' => Service::ARCHIVED,])
   ->andWhere([
       'or',
       ['client_service.status' => ClientService::STATUS_NEGATIVE],
       ['between', 'client_service.created', $start_date, $end_date]
      ])