SQL Query to Check for Dates Before a Given Time
I'm trying to get a SQL query to work to check for dates before a given time. It is intended to prevent reservation conflicts with this room booking website I am working on. Some of the syntax appears to be wrong, but I'm not quite sure what the correct syntax is. This is my query:
The roomID corresponds to a particular room, and the reservationDate is a date type in the database. The datestamp is a timestamp. Any ideas of what isn't right here?
$periodcheck="SELECT * FROM Reservations WHERE roomID='$roomID' OR
roomID=4 AND reservationDate<$datestamp ORDER BY reservationID DESC";
Does $datestamp need to be quoted, perhaps?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
if $datestamp is coming from an external (such as a programming language) or even just a string, as most likely since you're not binding your parameters, you'll need to use something date_format, or to_date.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)