Search interval dates Laravel / Eloquent?

2

How do I search the date range?

I searched and many places indicate how to search for date ranges according to the example below, but with no results.

$d1 = data2Mysql($dataI); // format Y-m-d
$d2 = data2Mysql($dataF); // format Y-m-d

$current = DB::table('ponto')
        ->whereBetween('data_inicial',[$d1,$d2])
        ->first();

The Eloquent correctly mounts SQL, but the result is null and there is data in the table where the range is being searched.

Query executed:

array(1) {
  [0]=>
  array(3) {
    ["query"]=>
    string(66) "select * from 'ponto' where 'data_inicial' between ? and ? limit 1"
    ["bindings"]=>
    array(2) {
      [0]=>
      string(10) "2018-01-12"
      [1]=>
      string(10) "2018-01-13"
    }
    ["time"]=>
    float(0.95)
  }
}
NULL
    
asked by anonymous 12.01.2018 / 18:50

1 answer

3

A teammate gave me an example in another language and using whereRaw of eloquent I got the expected result and I'm sharing:

   $d1 = data2Mysql($dataI); // format Y-m-d

    $current = DB::table('ponto')
        ->whereRaw('? between data_inicial and data_final', $d1)
        ->first();
    
12.01.2018 / 19:18