in my laravel app I'm trying to check if new records were created after a certain timestam (lastTimeFocused) the thing is I'm getting wrong results...
$newLikes = Like::where('liked_id','=',$request['user_id'])->where('created_at','>',$lastTimeFocused)->get();
Where lastTimeFocused is the last time the app screen was focused, here I'm gettign lots of results that were presumably created "after" but if I check these records the created_at timestamp shows it's not the case...
"lastTimeFocused": 2023-08-03T12:10:33.195Z,
created_at": "2023-08-03T11:56:32.000000Z
How is created_at supposed to be after lastTimeFocused? Maybe I have to format before compare?
I get lastTimeFocused with a simple javascript new Date() on the frontend
lastTimeFocusedyou shared is actually correct (remember theZat the end means "Zero offset" i.e. UTC time) then set your Laravel timezone settings toUTCinconfig/app.phpto ensure everything is in UTC on the server side. You can correct for the timezone in JavaScript. The browser is much more likely to know the timezone the user has set (and remember the user might choose to set a different timezone to what their location's IP is for good reasons). I would recommend to use UTC for everything on the server and correct for timezone in the browser.created_atshould be cast into a date type by Eloquent, this means$lastTimeFocusedhas to be something that Carbon can parse into a date. You can try using the query log. This will show the SQL query and might give you some ideas as to where the problem is.