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

swapnilmanew's avatar

wherebetween is not working in laravel

I am trying to fetch the data between two days but I am getting null records here is my code

I have set the datatype to store date as date

my request

Y-M-D
from date = 2022-10-12
to date = 2022-10-1
 return  tbl_attendance::whereBetween("created_at", [Carbon::parse($startDate), Carbon::parse($endDate)])->get();
0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

Your from_date is after your to_date

1 like
Sinnbeck's avatar

It cannot give you null. You would get an empty collection. If you are getting null, you have some other bug in your code (missing return?)

Please or to participate in this conversation.