Friday, March 17, 2017

Laravel Carbon date not being converted to UTC for ->where()

I have a carbon instance like that:

enter image description here

and in the database I have a column called "start", that has the value 2017-03-17 08:01:00.

The app's timezone is set to UTC, when I do:

MyModel::where('start', '=', $startDateTime)->get()

then I would expect that row to come up, but it does not, and the reason for that appears to be the fact that Eloquent does not properly convert the time, I have to manually do a

$startDateTime->timezone('utc')

in order to get the expected result. The start column is inside the $dates array in the model. Should't laravel automatically convert it to my app's timezone first (iny my case UTC)?



via Michael

Advertisement