Question

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!!!

Was it helpful?

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);

OTHER TIPS

Try formatting the date to date in the the database as ex to your desired format shown below

 $criteria->compare('date1',date("d-m-Y",strtotime($this->date1),true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top