• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

SQL Query based on dates

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Archer36

Member
Joined
Jun 18, 2004
Location
Michigan, US
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
 
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')
 
marker said:
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:
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.
 
Back