我有一个包含用户记录(姓名、名字、出生日期等)的表,我想按姓名或出生日期或所有可能的组合查找用户。
我的代码运行良好,但生日是以美国格式 (YYYY-MM-dd) 存储的,所以我必须以这种格式搜索日期以获得正确的记录。这真的很烦人,因为在德国我们使用欧洲格式(dd.MM.YYYY),我想按我们习惯的格式搜索日期。现在我需要帮助来为输入字段提供欧洲格式并获得正确的记录。
我希望,你明白我的问题。:)
这是我的控制器代码的摘录:
$name = $this->request->data['name'];
$forename = $this->request->data['forename'];
$birthdate = $this->request->data['birthdate'];
if($name || $forename || $birthdate){
$query = $this->find()
->where([
'name LIKE' => '%'.$name.'%',
'forename LIKE' => '%'.$forename.'%',
'birthdate LIKE' => '%'.$birthdate.'%'
]);
$number = $query->count();
$this->set('users', $this->paginate($query));
$this->set('_serialize', ['users']);
}
从我的角度来看,这是代码的相关部分:
foreach($users as $user):
h($user->name)
h($user->forename)
h($user->birthdate)
endforeach;
非常感谢。