Searching Formatted Date

Hi All,

I would like to get you idea on how can I create a search functionality with formatted dates and values. Using the default search function of the controller, we can search data directly from database.

For example:

DB Data:

USER_CODE = ‘0001’

NAME = ‘Stephen James’

REGISTRATION_DATE = ‘2013-07-14’

STATUS = ‘1’

The above data will be displayed in the search module like the following:

User code = ‘0001’

Name = ‘Stephen James’

Registration Date = ‘July 7, 2013’

Status = ‘Active’

The users will search for "Active" or "July" but no results found because the search() function is comparing "Active" = "1" and "July" = "2013-07-01".

What is the best to do in this kind of situation? Any ideas and suggestions can help a lot.

For ‘active’:

You can use dropdown in filter for search ‘active’ and reseult status=1 in db

In your Model::search:




$criteria->compare('MONTH(registration_date)', $this->registration_date);



This will let you search by the number of the month.

Then in you grid filter add a dropdown like this one




'filter' => array(

    '01' => 'January',

    '02' => 'February',

    '03' => etc...

)



So they will be able to select a month and it will do the search with the month number.

This is a way to do it but you can find your own way.

You can also change the value they input for a number. If they search for July, change it to 07, then search. But I think the first way is a lot easier.