How to convert date format before comparison in YII?

date-comparison, date-conversion, php, yii

Solution

There is one way of doing this, You have to use Date_Format function of mysql like follow:

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

Problem

I am using the default search provided by the YII CGridView. I have a text date field in the search criteria. I am trying to compare the date passed with the date in the database but they are not matching. I need to convert the format of the dates stored in the database as the date in the database also have time and I need to remove time before comparing the dates, But I cannot figure out a way to do this. In the default Search function() this is the line where I want to convert the dates before comparing. I have tried the conversion but this does not seem to work. ``` $criteria->compare(date("Y-m-d", strtotime('application_date')), date("Y-m-d", strtotime($this->application_date)),true); ``` Thanks for your help!!!

Original source