Results 1 to 3 of 3

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

  1. #1
    Join Date
    Oct 2006

    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:

    $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
    Does $datestamp need to be quoted, perhaps?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Aug 2005
    The Garden State
    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.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

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