Search date between two dates in search screen [message #1782] |
Thu, 30 October 2008 11:43 |
bonzo_bcn
Messages: 152 Registered: June 2008
|
Senior Member |
|
|
I have a 'person' table and would like to filter by birth date, is it possible in the search screen to filter the birth date with something like between '02/11/1986' and '05/11/1986' ?
I mean, can a date be filtered by ranges?
|
|
|
|
Re: Search date between two dates in search screen [message #1840 is a reply to message #1782] |
Fri, 14 November 2008 07:08 |
bonzo_bcn
Messages: 152 Registered: June 2008
|
Senior Member |
|
|
I just tried this, and it doesn't work for me.
In _cm_pre_getData() the two added fields aren't included in $fieldarray.
Also if I put this code in the detail screen:
$structure['main']['fields'][1][] = array('label' => 'Date From');
$structure['main']['fields'][1][] = array('field' => 'date_from');
$structure['main']['fields'][1][] = array('label' => 'To');
$structure['main']['fields'][1][] = array('field' => 'date_to');
the fields don't appear, I had to put this code to show the fields:
$structure['main']['fields'][] = array('label' => 'Date From');
$structure['main']['fields'][] = array('date_from' => 'date_from');
$structure['main']['fields'][] = array('label' => 'To');
$structure['main']['fields'][] = array('date_to' => 'date_to');
[Updated on: Fri, 14 November 2008 07:16] Report message to a moderator
|
|
|
|
Re: Search date between two dates in search screen [message #1843 is a reply to message #1782] |
Fri, 14 November 2008 11:14 |
bonzo_bcn
Messages: 152 Registered: June 2008
|
Senior Member |
|
|
So what should I do to make this work?
In _cm_pre_getData the tw date fields aren't in $fieldarray, therefore this code is never executed:
if (!empty($fieldarray['date_from']) OR !empty($fieldarray['date_to'])) {
$fieldarray['fecnac'] = rangeFromTo($fieldarray['date_from'], $fieldarray['date_to'], true);
unset($fieldarray['date_from']);
unset($fieldarray['date_to']);
} // if
I can see the search fields, but it doesn't filter correctly, are there any working example?
[Updated on: Fri, 14 November 2008 11:17] Report message to a moderator
|
|
|
|
|
|
Re: Search date between two dates in search screen [message #1847 is a reply to message #1782] |
Fri, 14 November 2008 12:49 |
bonzo_bcn
Messages: 152 Registered: June 2008
|
Senior Member |
|
|
Ok, looing at the example I found I needed more code:
if (empty($this->sql_search)) return $where;
// convert from string to an associative array
$fieldarray = where2array($this->sql_search, false, false);
if (!empty($fieldarray['date_from']) OR !empty($fieldarray['date_to'])) {
$fieldarray['fecnac'] = rangeFromTo($fieldarray['date_from'], $fieldarray['date_to'], true);
unset($fieldarray['date_from']);
unset($fieldarray['date_to']);
} // if
$this->sql_search = array2where($fieldarray);
Everything is working now, thanks.
|
|
|