Support the ongoing development of Laravel.io →
Eloquent Validation
Last updated 1 year ago.
0

That query should work, but you can also use the whereDate() clause.

$currentDate = date('Y-m-d');
$articles = Article::whereDate('expiration_date', '<=', $currentDate)->get();

You can also use the whereRaw() clause and get rid of the php date.

$articles = Article::whereRaw('expiration_date <= curdate()')->get();
Last updated 8 years ago.
0
Solution

Thanks thomastkim for your reply with your suggestions. My query was indeed almost correct, but I made a mistake with the comparison operator. Using '<=' would mean that I only get expired records.

To get the records that are not yet expired (with an expiration_date BEFORE the current date), this works:

$currentDate = date('Y-m-d');
$articles = Article::where('expiration_date', '>', $currentDate)->get();

Problem solved!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

php-it php-it Joined 22 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.