php - 如何使用 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;
}
解决方案
然后你应该使用'OR'语句。
$query->andFilterWhere(['or', [
['transaction_date' => $this->transaction_date],
['LIKE', 'transaction_date', $this->transaction_date]
]]);
或者享受 'BETWEEN' 声明,也可以用同样的方式声明。
推荐阅读
- python - Flask-sqlalchemy 按 unix 间隔过滤
- c++ - Win32 小堆栈大小的奇怪行为
- python - 当检查返回 false 时,如何停止 channel.purge 的限制减少?
- c - 定义不透明指针时防止不完整的类型声明?
- mysql - 如何提高大型数据库中 Date 的 SQL 查询速度
- python - 如果语句正确,Python 不会检测到函数循环
- java - 如何使用他的包装类创建一个接受并返回泛型类型的方法
- file-upload - 将文件从 Blazor WebAssembly 应用程序直接上传到 Blob 存储
- python - MariaDB在python中检查连接状态
- python - 创建一个 Numpy 数据集