Search code examples
mysqlsqllaraveldatedifference

Date between two values - Lavarel SQL


I have a structure table like this : Start_date End_date

Now with today's date, I should go and get all the data including from Start_Date and End_Date, what can I do?

I tried with

SELECT * 
FROM text 
WHERE Start_date BETWEEN '2021-10-10' AND '2021-10-08' 
OR End_date BETWEEN '2021-10-08' AND '2021-10-10

but to no avail ...


Solution

  • The whereBetween method in Laravel will determine if an items value is between the given range.

    $start = '2021-10-08';
    $end = '2021-10-10';
    
    Text::whereBetween('start_date', [$start, $end])
          ->whereBetween('end_date', [$start, $end])
          ->get();