-2

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.

Raju Ahmed
  • 1,282
  • 5
  • 15
  • 24
prasobh
  • 3
  • 2
  • You need to write PHP code for it. What have you written so far? – Luuk Mar 31 '22 at 14:03
  • Does this answer your question? [How to Check if value exists in a MySQL database](https://stackoverflow.com/questions/11292468/how-to-check-if-value-exists-in-a-mysql-database) – Luuk Mar 31 '22 at 14:08
  • Question little bit not clear. Do you want to check a random date equal to one of the given dates? – Hishan_98 Mar 31 '22 at 17:10

1 Answers1

0
$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 ;
malick
  • 1
  • 3