There are several options for making the two date strings match. Firstly, we have to know which of the following is correct and then we can progress.

Originally Posted by
ianhaney
.
the column called sales_month stores the date in the format of YYYY/MM/DD
.

Originally Posted by
ianhaney
.
it was yyyy-mm-dd and the datepicker was in format dd-mm-yyyy
.
I'll assume that the date format required for the database query is YYYY-MM-DD (the standard ISO 8601 format) but, if that's wrong, you'll need to change the code below.
The simplest way to fix this is to get the date-picker to produce a date string in the YYYY-MM-DD format. However, if that's not possible (or appropriate for your users), then the date-picker string needs to be broken down into it's constituent parts and reassembled in the correct format. It's important to remember that the format of the dates in the URI must always be the same whether the call to search-data.php comes from the date-picker page or is a recursive call from the search-data page itself. This narrows the choice down to two possible places where the translation can occur.
The first is in the date-picker page and, as this page is running on the browser, this will require some JavaScript. A simple function can translate the date codes from the date-picker into ISO 8601 format before they are inserted into the URI passed to search-data.php. That way no further translation is needed.
The second method is to translate the date-picker output immediately before the SQL query is assembled and, as this is server-side code, PHP will be required. Here's how to do that.
Firstly copy the function below and paste near the top of your page:
PHP Code:
function translateDate($date) {
$dateArray = explode("-", $date); /* This creates an array of the three parts of the string in $date. */
return $dateArray[2].'-'.$dateArray[1].'-'.$dateArray[0]; /* Now stitch the parts back together in the reverse order. */
}
Now add a couple of calls to the function before assembling the query string (you'll have to do this in two places, once for query which establishes the size of the data and the second one for the retrieval of the data):
PHP Code:
$start_date = translateDate($d1);
$end_date = translateDate($d2);
$query = "SELECT * FROM purchased_software WHERE sales_month BETWEEN $start_date AND $end_date ORDER BY id LIMIT $start_from, $per_page";
If that doesn't fix it, you'll have to post the source of the page which is currently working.
Bookmarks