After retrieval of a string variable dd-mm-yyyy, I converted it into a string format yyyy-mm-dd in order to perform an sql query from a mysql table where the attribute is a date attribute format yyyy-mm-dd. I need to compare my string variable with the date in the table. I am using MyTable::model()->find(date(myvariable) >= table_attribute) but it does not work and I have found that a find() without condition returns values for the date in the format dd-mm-yyyy which means that I do not have to convert my variable in the yyyy-mm-dd format.
I have tried a multiple of ways but have not succeeded in doing this. strotime function of php does not work with find() because I need to use mysql functions in the query. Can anybody please help?
Thanks for your prompt reply. The code is in my controller. It is supposed to update a dropdown list in my form view where I need to have only the data which satisfies the condition carried out in the controller. It works fine with the one condition which is not related to date. But when I add another condition relative to the date, it is not giving satisfatory results.
In one of my trials, I commented the conversion of the variable $arrival when I noted that the query returns $rep->arrival in the format mm-dd-yyyy. I had thought it would have returned it in the format yyyy-mm-dd.
if(strtotime($date->target_date)>=strtotime($list['Date']))
or
if(strtotime($date->target_date)=strtotime($list['Date']))
or
if(strtotime($date->target_date)<strtotime($list['Date']))
Rajith, I want to put the condition in the find() method. Strtotime does not work here. If I do it outside the function, then I’ll have to use findAll() instead of find(). I wanted to avoid that. If I find only 1 occurrence satisfying the condition, I do not add it to the dropdown list. With findAll(), I’ll have to check for this condition in each element of the array which is longer. Maybe I am a bit lazy…