'how to check whether the date comes from a form is the same as the date stored in mysql database in php

I have a MySQL database table called "booking" and fileds called "arrival" and "diparture".

arrival diparture
2022-03-22 2022-03-23

now I want to check whether a random date is present within these two dates(date in the database). I want it to be done in PHP.

I don't know the easy way to do it.



Solution 1:[1]

$dateChecked = '2022-03-20' ;
$sqlQuery = "SELECT * FROM booking WHERE arrival <= :dateChecked AND diparture >= :dateChecked";
$dateStatement = $mysqlClient->prepare($sqlQuery);
$dateStatement->execute(['dateChecked' => $dateChecked]);
$dates = $recipesStatement->fetch();
        
if ($dates)
    return true ;
        else
   return false ;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 malick