如何使用ActiveRecord过滤带有时区列的时间戳

时间:2019-05-29 14:32:50

标签: php postgresql yii2

  

SQLSTATE [42883]:未定义的函数:7错误:运算符不存在:没有时区的时间戳~~未知   第1行:... ERE(“交易日期” = $ 1)和(“交易日期”像$ 2)   ^   提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。

public function search($params)
    {
        $query = EpayslipAudit::find()->orderBy(['id'=>SORT_DESC]);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'transaction_date' => $this->transaction_date,
        ]);
        $query->andFilterWhere(['like', 'party_id', $this->party_id]);
        $query->andFilterWhere(['like', 'name', $this->name]);
        $query->andFilterWhere(['like', 'email', $this->email]);
        $query->andFilterWhere(['like', 'period', $this->period]);
        $query->andFilterWhere(['like', 'status', $this->status]);
        $query->andFilterWhere(['like', 'action_by', $this->action_by]);
        $query->andFilterWhere(['like', 'transaction_date', $this->transaction_date]);

        return $dataProvider;
    }

1 个答案:

答案 0 :(得分:0)

然后您应该使用'OR'语句。

$query->andFilterWhere(['or', [
   ['transaction_date' => $this->transaction_date],
   ['LIKE', 'transaction_date', $this->transaction_date]
]]);

或者享受“ BETWEEN”声明,可以用相同的方式声明它。