Previous Thread
Next Thread
Print Thread
Rate Thread
#272258 04/13/2004 1:34 AM
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
I'm missing something obvious here -

Here's my query:


SELECT SUM(Miles) FROM w3t_Miles WHERE User IN (207,215,225) AND Date > 2003-08-01 AND Date < 2004-05-06



OK - this grabs my user numbers 207, 215 and 225. That part works fine. Each record has a date stamp - I want to get ones newer than 8-1-2003 but before 5-6-2004.

Yet it always seems to return no results. If I take the second Date conditional out - it returns results.

Is there a better way in MySQL to grab a range of dates????

Thanks!

Sponsored Links
Daine #272259 04/13/2004 8:35 AM
Joined: Nov 2001
Posts: 745
Admin Emeritus
Admin Emeritus
Offline
Joined: Nov 2001
Posts: 745
SELECT SUM(Miles) FROM w3t_Miles WHERE User IN (207,215,225) AND Date BETWEEN 2003-08-01 and 2004-05-06

Try that and see if it works

Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Very odd - I must be doing something else wrong - that didn't work either - I even took the user clause out just to simplify:

SELECT SUM( Miles )
FROM w3t_Miles
WHERE Date
BETWEEN 2003-08-01 AND 2004-05-06

Thanks for the suggestion though.

Daine #272261 04/13/2004 9:35 AM
Joined: Nov 2001
Posts: 745
Admin Emeritus
Admin Emeritus
Offline
Joined: Nov 2001
Posts: 745
One thing I do when I'm having trouble with a query is I will go and build a mock setup in Access, and play with it in there until I get it tweaked. Then I just use the SQL view to get the syntax that works and port that into my code.

It saves time as opposed to change your code, upload, test. And it doesn't cause any damage to any thing

domino #272262 04/13/2004 10:05 AM
Joined: Oct 2003
Posts: 2,305
Old Hand
Old Hand
Joined: Oct 2003
Posts: 2,305
what format is the actual date stamp Josh is it in UNIX? or GMT as it appears above?

Sponsored Links
234234 #272263 04/13/2004 12:20 PM
Joined: Aug 2002
Posts: 1,191
Kahuna
Kahuna
Joined: Aug 2002
Posts: 1,191
Maybe it is daft but why not try it with enclosing the date in quotes like

....
BETWEEN '2003-08-01' AND '2004-05-06'


Nikos
Joined: Oct 2003
Posts: 2,305
Old Hand
Old Hand
Joined: Oct 2003
Posts: 2,305
your right it should be encased in '

Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Eureka!

Yup the quotes did the trick. Funny that with only one date clause - it worked without the quote. It's a MySQL Date field so I knew I had to be overlooking the abvious. Thank you!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)