Guest Posted October 16, 2020 Share Posted October 16, 2020 (edited) How to build SQL for date filtering in HelperList? I see values like: <input type="hidden" id="my_customFilter_date_0" name="my_customFilter_date[0]" value="2020-10-01"> and <input type="hidden" id="my_customFilter_date_1" name="my_customFilter_date[1]" value="2020-10-30"> Example: 1. the From date is empty and the To date has a value 2. date From has value and date It is empty 3. the date From has a value and the date To has a value When I build SQL, it still returns the date '0000-00-00'. if (Tools::getValue('my_customFilter_date[0]')) {$date_from = Tools::getValue('my_customFilter_date[0]');} else {$date_from = '0000-00-00';} if (Tools::getValue('my_customFilter_date[1]')) {$date_to = Tools::getValue('my_customFilter_date[1]');} else {$date_to = '0000-00-00';} $this->filter_date = ' AND a.date_from >= '."'".$date_from."'".' AND a.date_to <= '."'".$date_to."'"; Thank you Edited October 16, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
EvaF Posted October 16, 2020 Share Posted October 16, 2020 try this: $dateRange = Tools::getValue('my_customFilter_date'); if ($dateRange [0]) {$date_from = $dateRange [0];} else {$date_from = '0000-00-00';} if ($dateRange [1]) {$date_to = $dateRange [1];} else {$date_to = '0000-00-00';} Link to comment Share on other sites More sharing options...
Guest Posted October 16, 2020 Share Posted October 16, 2020 6 minutes ago, EvaF said: try this: $dateRange = Tools::getValue('my_customFilter_date'); if ($dateRange [0]) {$date_from = $dateRange [0];} else {$date_from = '0000-00-00';} if ($dateRange [1]) {$date_to = $dateRange [1];} else {$date_to = '0000-00-00';} Oh yes. Thank you very much. My brain doesn't think anymore 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now