如何在YII中转换比较前的日期格式


How to convert date format before comparison in YII?

我使用的是YII CGridView提供的默认搜索。我在搜索条件中有一个文本日期字段。我正在尝试将传递的日期与数据库中的日期进行比较,但它们不匹配。我需要转换数据库中存储的日期的格式,因为数据库中的日期也有时间,我需要在比较日期之前删除时间,但我无法找到实现这一点的方法。

在默认的搜索函数()中,这是我想在比较之前转换日期的行。我试过转换,但似乎不起作用。

$criteria->compare(date("Y-m-d", strtotime('application_date')),
date("Y-m-d", strtotime($this->application_date)),true);

谢谢你的帮助!!!

有一种方法可以做到这一点,您必须使用mysql的Date_Format函数,如下所示:

$criteria->compare('DATE_FORMAT(application_date,"%Y-%m-%d")',date("Y-m-d", strtotime($this->application_date)),true);

尝试将数据库中的日期设置为ex格式,如下所示

 $criteria->compare('date1',date("d-m-Y",strtotime($this->date1),true);