Level 51
You can use whereTime instead of whereDate.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Help! I need to publish and hide a post by specific date and time. I tried both codes, but it doesn't work. It works fine if retrieve with just date, but I need to retrieve it with time.
$latest_article=Article::whereDate('published_at', '<=', Carbon::now())
->WhereDate('expired_at', '>', Carbon::now())
->Where('status', 1)
->latest()
->limit(3)
->get();
$latest_article=Article::whereDate('published_at', '<=', Carbon::now())
->WhereDate('expired_at', '>', Carbon::now())
->whereTime('published_at', '<=', Carbon::now())
->WhereTime('expired_at', '>', Carbon::now())
->Where('status', 1)
->latest()
->limit(3)
->get();
Please or to participate in this conversation.