1

my query is not working, basically im trying to get records between dates_time but for some reason is not working, i already checked on my db and should return one result. Im using Carbon and Eloquent from Laravel.

$todayFictitiasDate = new Carbon("2017-08-09 16:00:00");

//records between 2017-08-09 17:00:00 and 2017-08-09 21:00:00

$liveMatches = SoccerMatch::where('date_time','>=', $todayFictitiasDate->addHour())
                        ->where('date_time','<=',$todayFictitiasDate->addHours(5))
                        ->get();

I also tried this way:

 $liveMatches = SoccerMatch::whereBetween('date_time',array($todayFictitiasDate->addHour(),$todayFictitiasDate->addHours(5)))
            ->get();

My record on db:

id= 1
title =  something
date_time = 2017-08-09 18:00:00

Works this way but dont no why: For some reason the datetime keeps adding hours when i isnert on eloquent, dont no why, it works this way:

$n  = (new Carbon("2017-08-09 16:00:00"))->addHour();
$n5 = (new Carbon("2017-08-09 16:00:00"))->addHours(5);

$liveMatches = SoccerMatch::whereBetween('date_time',array($n,$n5))
            ->get();
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Marco Santos
  • 41
  • 1
  • 8

0 Answers0