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
2
Answers
Parse
$lastTimeFocused
using Carbon and then make your comparison:You should format date and time before compare
You can format using Carbon library