首页 > 解决方案 > 如何使用 ActiveRecord 过滤带有时区列的时间戳

问题描述

SQLSTATE [42883]:未定义函数:7 错误:运算符不存在:没有时区的时间戳~~未知第 1 行:...ERE ("transaction_date"=$1) AND ("transaction_date" LIKE $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;
    }

标签: phppostgresqlyii2

解决方案


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

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

或者享受 'BETWEEN' 声明,也可以用同样的方式声明。


推荐阅读