Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

320
Vistas
Laravel whereBetween with dates why not working?

Here is my code:

$arr = Event::select('user_id', 'start', 'end')
    ->where('start', '!=', $from)
    ->whereBetween('start', [$from, $till])
    ->orWhere(function($query) use ($from, $till) {
        $query->where('end', '!=', $till)
            ->whereBetween('end', [$from, $till]);
    })->get();

start value: 2021-07-11 9:00:00 end value: 2021-07-11 15:00:00

$from value: 2021-07-11 10:30:00 $till value: 2021-07-11 13:00:00

I tried with Carbon as well, but the query result is nothing. What is the problem? Also I tried with:

$arr = Event::where('start', '>', $from)
    ->where('start', '<', $till)    
    ->get();

Simply not working!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The main code segment has some little flaw with

wherebetween('start', [$from, $till])

Because your start date doesn't lies between your from and till value. That returns nothing actually.

Try with your second solution. With a lil change in it.

$arr = Event::where('start', '<=', $from)
->where('end', '>=', $till)    
->get();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda