solarmoon
solarmoon

Reputation: 21

Check whether the date time is in between two date time in database Laravel 6

I'm newbie in php laravel. I'm currently working in my appointment system. I have two date, the start and end. I want to check if the date and time is in between of these two. Is there a Validation in between two date?

Upvotes: 0

Views: 129

Answers (1)

Foued MOUSSI
Foued MOUSSI

Reputation: 4813

Request Validation

$validation = $this->validate($request, [
    'date' => 'required|date_format:Y-m-d H:i:s|after_or_equal:startDateColumn|before_or_equal: endDateColumn',
    //...
]);

Elequent Query Check

$date = date('Y-m-d H:i:s');

$count = Model::where('startDateColumn', '>=', $date)
              ->where('endDateColumn', '<=', $date)->count();

Then

if($count > 0) {
  // ...
} else {
 // ...
}

Upvotes: 1

Related Questions