Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date format before comparison in YII?

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

like image 768
Anshuman Jasrotia Avatar asked Jan 28 '26 20:01

Anshuman Jasrotia


1 Answers

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);
like image 99
sarvesh Avatar answered Jan 31 '26 16:01

sarvesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!