I'm trying to compare the date pass from previous page with the date (unix timestamp format) stored in database. My code as below. Error : Recoverable fatal error: Object of class DateTime could not be converted to string in C:\xampp\htdocs\check.php on line 14
How should I modify it to be able to compare with the "datetime2" and store as the 10 digit unixtime.
Basically I do not want to convert it to normal date. just store as it is, 10 digit unixtimestamp.
Please help to look into the foreach loop as well. I want to check if the selected date has appeared in database.
Thank you
<?PHP
session_start();
$userid = $_SESSION['userid'];
$datetime = $_POST['datetime'];
$available = 0;
$date = $datetime; $datetime2 = new DateTime($date); echo $datetime2->getTimestamp();
$con = mysqli_connect('localhost', 'root', 'abc123');
$query = "SELECT COUNT * FROM reservation WHERE InstallDate='" . $datetime2 . "'";
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con, 'btr');
foreach(mysqli_query($con, $query )as $row)
{
if($row <=1)
{
$available = 1;
echo $available;
}
}
mysqli_close($con);
?>