I want to check if today's date is between to dates dat are stored in the database. Right now I do this with laravel eloquent:
return Set::where('type', $type)
->where('active_from', '<=', date("Y-m-d"))
->where('active_until', '>=', date("Y-m-d"))
->first();
Is this correct?
Assuming both active_from
and active_until
contains only dates it's correct, but if they contain dates with times you should probably use whereDate
instead of where
like so:
return Set::where('type', $type)
->whereDate('active_from', '<=', date("Y-m-d"))
->whereDate('active_until', '>=', date("Y-m-d"))
->first();
Also, looking at the code I'm pretty sure you should use operators the other way: active_from
should be >=
and active_until
should be <=
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With