|
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!
|
|
|
|
Joined: Nov 2001
Posts: 745
Admin Emeritus
|
Admin Emeritus
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.
|
|
|
|
Joined: Nov 2001
Posts: 745
Admin Emeritus
|
Admin Emeritus
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
|
|
|
|
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?
|
|
|
|
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!
|
|
|
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.
|
|
Posts: 1,157
Joined: July 2001
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|