vendredi 24 juin 2016
Laravel - query data from mysql between dates
I am having an issue getting rows from my table using the below query, the expected behaviour is:
user selects start/end date in a form, hits submit and the data passes to the function & it is then used in the query.
The data from the form is coming in fine & I have verifed the dates are coming into the query, but for some reason the query always returns zero results? When I strip out the WHERE statement for the dates, the query works fine & produces results, so the issue is to do with the dates.
$fromDate = $request->fromDate;
$toDate = $request->toDate;
$data = cc_table::all('*')
->where('link', '1')
->where('created_at', '>', $fromDate)
->where('created_at', '<', $toDate)
->toArray();
The dates from the form are formatted as dd/mm/yyyy, and the created_at date is a timestamp, however for testing I did change the created_at to be DATE (dd/mm/yyyy) however the query still returns zero rows.
FYI - I am just using jquery datepicker on my form:
$(function() {
$( "#fromDate" ).datepicker();
});
</script>
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire