BaronK
BaronK

Reputation: 13

PHP Date in MySQL Query

What's wrong with this query?

 $query = $db->query("select username from roomsbooked where username='$_SESSION[username]' and timeslot='$_SESSION[timeslot]' and number='$_SESSION[roomNumberToBook]' and dateofbooking='$_SESSION[dateEntered]'");

The dateofbooking field in the database is a "date" field.

$_SESSION[dateEntered] is defined as:

$_SESSION["dateEntered"] = DateTime::createFromFormat('d/m/Y', $_POST["Date"]);

When the script runs it gets to the query but nothing happens there after.

Upvotes: 0

Views: 48

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

MySQL Doesnt use d/m/Y format, you have to do

DateTime::createFromFormat('Y-m-d', $_POST["Date"]);

Upvotes: 3

Related Questions