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

david2000's avatar

future date check

I have a small problem in my dates. For example, I encoded the following date:

date training : 10/09/2019 | hour_start : 08:00 | hour_end : 10:00 | motorbike : 000001

Then, I want to encode for on 11/09/2019 the same informations

My checking compares only the hours (start & end) and no the date.

So, for my example, I have a blocking...

My problem is in my code

$date_seance = $request->get('date_seance'); 
$hour_start = $request->get('hour_start'); 
$hour_end = $request->get('hour_end'); 
$fk_motorbike = $request->get('fk_motorbike');
$fk_student = $request->get('fk_student');
$fk_former = $request->get('fk_former');
$fk_typeseance = $request->get('fk_typeseance');


$conflictTraining = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
->whereDate('date_seance', "=" , $date_seance)  
->where('hour_start', "<=" , $request->get('hour_start')) 
->where('hour_end', ">=" , $request->get('hour_end'))
->where('fk_former', $request->get('fk_former'))
->first();

 if(isset($conflictTraining)){
            return redirect()->route('trainings.index')
             ->with('error', 'The training is already booked');
        }

For information my hours are in format string is it a problem ?

 Schema::create('trainings', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('date_seance');
            $table->string('hour_start');
            $table->string('hour_end');

Thank you for your help.

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@david2000 First for your time question, yes it is a problem.. How can you compare if a String is >= or <= then?

Those field should also be date and time, or timestamps.

Then for the date, make sure that you are comparing using the same format. The easiest way might be to just parse the date that comes in from the input:

->whereDate('date_seance', "=" , Carbon::parse($date_seance))  
1 like
david2000's avatar

Hello @nakov,

Great ! Thank you, my problem is solved.

Thank you a lot !

Please or to participate in this conversation.