www.webdeveloper.com
Results 1 to 3 of 3

Thread: SQL Query to Check for Dates Before a Given Time

  1. #1
    Join Date
    Oct 2006
    Posts
    14

    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:

    Code:
    $periodcheck="SELECT * FROM Reservations WHERE roomID='$roomID' OR 
    	roomID=4 AND reservationDate<$datestamp ORDER BY reservationID DESC";
    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?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,604
    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

    eBookworm.us

  3. #3
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles