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

TheBlueDragon's avatar

how to compare with date in where()

hello every one, iam trying to get the result where the date field is bigger than current date (( like in next days or weeks ))

i try following

ExamsSchedule::whereDate('exam_date', '>=', Carbon::now()->toDateString());

ExamsSchedule::where('exam_date', '>=', Carbon::now()->toDateString());

even i try to hard code it so i can see if there is a problem or something

ExamsSchedule::where('exam_date', '>=', '2016-10-28');

but same issue

anyone have something similar

btw my date field (exam_date) is in date type in db like (2016-10-23)

0 likes
4 replies
TheBlueDragon's avatar
TheBlueDragon
OP
Best Answer
Level 15

@tomi hmmm this way its working but why not working with the where with model object, the issue now i cant use the other methods in relations =(

i found the issue >_< i didnt add the get() at the end

ExamsSchedule::where('exam_date', '>=', Carbon::now()->toDateString())->get();

thx

1 like
vuulr's avatar

Any idea how can we compare 2 diff dates like if created_date = #date1 or created_date=#date2

mohasin2911's avatar
$from = date('2018-01-01');

$to = date('2018-05-02');

Reservation::whereBetween('reservation_from', [$from, $to])->get();

Please or to participate in this conversation.