Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
Laravel whereBetween con fechas ¿por qué no funciona?

Aquí está mi código:

 $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();

valor inicial: 2021-07-11 9:00:00 valor final: 2021-07-11 15:00:00

$desde valor: 2021-07-11 10:30:00 $hasta valor: 2021-07-11 13:00:00

También probé con Carbon, pero el resultado de la consulta no es nada. ¿Cuál es el problema? También probé con:

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

¡Simplemente no funciona!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El segmento de código principal tiene algún pequeño defecto con

where between('inicio', [$desde, $hasta])

Porque su fecha de inicio no se encuentra entre su valor desde y hasta. Eso no devuelve nada en realidad.

Prueba con tu segunda solución. Con un pequeño cambio en él.

 $arr = Event::where('start', '<=', $from) ->where('end', '>=', $till) ->get();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!