Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ipibk's avatar
Level 1

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.

1 like
4 replies
tisuchi's avatar

@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).

6 likes
ipibk's avatar
Level 1

Sorry. It's a typo. But still having the same issu.

4 likes
tisuchi's avatar
tisuchi
Best Answer
Level 70

@ipibk Have you tried this way?

$from = date("Y-m-d", strtotime("-2 months"));

$data = Post::whereDate('uploaded_at' , '>=' , $from)->paginate(20);
6 likes

Please or to participate in this conversation.