Reputation: 173
The following query works fine when not using a variable for the date&time. However, I would like to use a variable for "2014-09-29 09:00:00".
$query = ' SELECT *
FROM dateTime1
WHERE dateBooked="2014-09-29 09:00:00"';
(The "dateBooked" field is of datetime format.)
I below doesn't work:
$dateX = '2014-09-29 09:00:00';
$query = ' SELECT *
FROM dateTime1
WHERE dateBooked=' .$dateX;
Upvotes: 0
Views: 985
Reputation: 1210
Try this:
$dateX = '2014-09-29 09:00:00';
$query = ' SELECT *
FROM dateTime1
WHERE dateBooked="' . $ dateX . '"';
Upvotes: 1
Reputation: 219794
You're missing quotes around your date:
$query = " SELECT *
FROM dateTime1
WHERE dateBooked='" .$dateX . "'";
or
$query = " SELECT *
FROM dateTime1
WHERE dateBooked='$dateX'";
Upvotes: 2