mercredi 24 mai 2017

Laravel's whereBetween not including date from

Note: Code should work for postgres and mysql.

I want to query a table by date_from and date_to. Let's say there is a date range with format: ('d-m-Y')

Foo:

[
 {'id': 1, "created_at": "2017-05-20 11:18:00"},
 {'id': 2, "created_at": "2017-05-24 11:38:36"}
]

Code:

$format = 'd-m-Y';
$df = $request->input('date_from');
$dt = $request->input('date_to');
$date_from = Carbon::createFromFormat($format, $df);
$date_to = Carbon::createFromFormat($format, $dt);

Foo::whereBetween('created_at', [$date_from, $date_to])->get()->toArray();

When I query date_from = '20-05-2017' and date_to = '20-05-2017', I see an empty array. I expect to see 20-05-2017 Foo's regardless. If I date_from = '19-05-2017' and date_to = '21-05-2017', I see 20-05-2017's array.

What's wrong with whereBetween?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qVwtga
via IFTTT

Aucun commentaire:

Enregistrer un commentaire