How to change date format when filtering OpenCart 2.3?

0 like 0 dislike
4 views
Hi! I have a filter orders by date. Now, the problem is that the filter only works when the date format is YYYY-MM-DD, if I change the attribute data-date-format the date format from DD.MM.YYYY, the filter finds nothing more. Although in the url all the queries remain. Connected library bootstrap-datetimepicker.js

Filtering works by checking the post and then add a condition to the query
public function getOrders($data = array()) { $sql = "SELECT o.order_id, o.firstname, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o"; $sql .= "WHERE o.order_status_id > '0' AND o.customer_id = '" . (int)$this->customer->getId() . "' AND o.order_status_id > '0' AND o.store_id = '" . (int)$this->config->get('config_store_id')."'"; if (!empty($data['filter_customer'])) { $sql .= "AND CONCAT(o.order_id, ' ') LIKE '%" . $this->db->escape($data['filter_customer']) . "%'"; } if (!empty($data['filter_date_from'])) { //add the query to the database $sql .= "AND DATE(o.date_added) >= '" . $this->db->escape($data['filter_date_from']) . "'"; } if (!empty($data['filter_date_to'])) { //add the query to the database $sql .= "AND DATE(o.date_added) <= DATE('" . $this->db->escape($data['filter_date_to']) . "')"; } $sort_data = array( 'o.order_id', 'customer', 'status', 'o.date_added', 'o.date_modified', 'o.total' ); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= "ORDER BY" . $data['sort']; } else { $sql .= "ORDER BY o.order_id"; } if (isset($data['order']) && ($data['order'] == 'DESC')) { $sql .= "DESC"; } else { $sql .= "ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 10; } $sql .= "LIMIT" . (int)$data['start'] . "," . (int)$data['limit']; } $query = $this->db->query($sql); return $query->rows; }


$('#button-filter').on('click', function() { url = 'index.php?route=account/order'; var filter_date_from = $('input[name=\\'filter_date_from\\']').val(); if (filter_date_from) { url += '&filter_date_from=' + encodeURIComponent(filter_date_from); } var filter_date_to = $('input[name=\\'filter_date_to\\']').val(); if (filter_date_to) { url += '&filter_date_to=' + encodeURIComponent(filter_date_to); } location = url; });


Thanks in advance!
by | 4 views

1 Answer

0 like 0 dislike
so convert the values to a single format, what's the problem?
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
1,054 users