Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

SQL Query based on dates

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 07-22-05, 12:44 AM Thread Starter   #1
Archer36
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

Archer36 is offline   QUOTE Thanks
Old 07-22-05, 08:22 AM   #2
shortyes
Member



Join Date: Oct 2002
Location: Tampa, FL

 
Just set the where statement to be x>July 20 and x < july 22
shortyes is offline   QUOTE Thanks
Old 07-22-05, 08:51 AM Thread Starter   #3
Archer36
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

Archer36 is offline   QUOTE Thanks
Old 07-22-05, 09:39 AM   #4
Krieger
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.
Krieger is offline   QUOTE Thanks
Old 07-22-05, 01:29 PM Thread Starter   #5
Archer36
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

Archer36 is offline   QUOTE Thanks
Old 07-24-05, 08:27 PM   #6
marker
Member

 
marker's Avatar 

Join Date: Mar 2005

 
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
marker is offline   QUOTE Thanks
Old 07-24-05, 09:40 PM Thread Starter   #7
Archer36
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.

__________________
"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


Last edited by Archer36; 07-24-05 at 10:25 PM.
Archer36 is offline   QUOTE Thanks
Old 07-25-05, 07:32 PM   #8
marker
Member

 
marker's Avatar 

Join Date: Mar 2005

 
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
marker is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 03:01 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?