Results 1 to 8 of 8
  1. #1
    Member Archer36's Avatar
    Join Date
    Jun 2004
    Location
    Michigan, US

    SQL Query based on dates

    Im sure there is a way to do this but, does anyone know how to make MySQL do a query between two dates? Lets say I want to query all messages posted between July 20 - July 22 but none others? BTW I am doing this in php too.

    Thanks
    "We will always remember. We will always be proud. We will always be prepared, so we may always be free."
    -- Fmr. President Ronald Reagan

    "We must all hang together, gentlemen...else, we shall most assuredly hang separately"
    -- Benjamin Franklin

    "Freedom is not free, that it comes with the highest of sacrifices. The price of blood"
    -- 300


  2. #2
    Member
    Join Date
    Oct 2002
    Location
    Tampa, FL
    Just set the where statement to be x>July 20 and x < july 22

  3. #3
    Member Archer36's Avatar
    Join Date
    Jun 2004
    Location
    Michigan, US
    Oh ok I thought about doing that but it just did not seem to be right.
    "We will always remember. We will always be proud. We will always be prepared, so we may always be free."
    -- Fmr. President Ronald Reagan

    "We must all hang together, gentlemen...else, we shall most assuredly hang separately"
    -- Benjamin Franklin

    "Freedom is not free, that it comes with the highest of sacrifices. The price of blood"
    -- 300


  4. #4
    Member
    Join Date
    Jan 2002
    Location
    North of Boston, MA
    Yeap that's the way it works... seems odd, but it makes the most sense when you think about it.

  5. #5
    Member Archer36's Avatar
    Join Date
    Jun 2004
    Location
    Michigan, US
    Yea it works great too, thanks!
    "We will always remember. We will always be proud. We will always be prepared, so we may always be free."
    -- Fmr. President Ronald Reagan

    "We must all hang together, gentlemen...else, we shall most assuredly hang separately"
    -- Benjamin Franklin

    "Freedom is not free, that it comes with the highest of sacrifices. The price of blood"
    -- 300


  6. #6
    There is usually a "BETWEEN" predicate which makes the query a little cleaner:

    SELECT *
    FROM Orders
    WHERE (OrderDate BETWEEN '1/1/2004' AND '12/31/2005')
    "I've tried everything. I have not failed. I've just found 10,000 ways that won't work." - Thomas A. Edison


    My Heatware

  7. #7
    Member Archer36's Avatar
    Join Date
    Jun 2004
    Location
    Michigan, US
    Quote Originally Posted by marker
    There is usually a "BETWEEN" predicate which makes the query a little cleaner:

    SELECT *
    FROM Orders
    WHERE (OrderDate BETWEEN '1/1/2004' AND '12/31/2005')
    Great, ill give that a shot too, it looks more fitting for what the query to do. Thanks!

    Just one question, before I change to the new code I am using two variables in place of the two dates, I am assuming this would work the same just making sure before I change it.
    Last edited by Archer36; 07-24-05 at 11:25 PM.
    "We will always remember. We will always be proud. We will always be prepared, so we may always be free."
    -- Fmr. President Ronald Reagan

    "We must all hang together, gentlemen...else, we shall most assuredly hang separately"
    -- Benjamin Franklin

    "Freedom is not free, that it comes with the highest of sacrifices. The price of blood"
    -- 300


  8. #8
    Should work with variables, I do it all the time. However, my expertise is in MS SQL Server not MySQL, but I cannot imagine why it would function any differently.
    "I've tried everything. I have not failed. I've just found 10,000 ways that won't work." - Thomas A. Edison


    My Heatware

Posting Permissions

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