Laravel query has wrong output
Laravel provide me the wrong output for date field query. I have a uploaded_at column in database having type as timestamp.
This is my query-
$from = date("d-m-Y", strtotime("-2 months"));
$data = Post::where('uploaded_at' , '>' $from)->paginate(20);
This piece of code is giving all the data from the post table where I needed only the last 2 months post.
@ipibk Is your code executing properly? I noticed that there is a typo.
It should be like that
$data = Post::where('uploaded_at' , '>', $from)->paginate(20);
instead of
$data = Post::where('uploaded_at' , '>' $from)->paginate(20);
You forget to add , (comma).
Sorry. It's a typo. But still having the same issu.
@ipibk Have you tried this way?
$from = date("Y-m-d", strtotime("-2 months"));
$data = Post::whereDate('uploaded_at' , '>=' , $from)->paginate(20);
Please or to participate in this conversation.