DB Error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2

SELECT * FROM `user` the_table WHERE the_table.userid = DB Error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2

SELECT * FROM `user` the_table WHERE the_table.userid = MySQL query date ranges? - iTechForums
Login
Search
Welcome to the iTechForums.
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
To register now click here.
Latest Threads
Advertisements
Forum Statistics
Threads:
Posts: 3
Members:
Number of Users Online:
Welcome to our newest member,
Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2008, 02:33 PM
gnomie_jones gnomie_jones is offline
Junior Member
 
Join Date: May 2008
Posts: 5
Default

MySQL query date ranges?


I'm trying to pull records from a range of datetime fields. The results are coming together as expected, however the high range doesn't display any results. So if I query records between 2008-05-04 and 2008-05-08 the records stop without displaying the 2008-05-08 records, however anything beween 05 and 07 will show up...weird.

Here's my query, i've tried many variations and they all have the same result


SELECT * FROM timecard WHERE time_in >= '2008-05-03' AND time_in <= '2008-05-08'


I could put a bump into my php to add a day to the date, but I'd rather figure out what I'm doing wrong and fix it within the query

any help will be much appreciated - thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 05-15-2008, 02:34 PM
Blackcompe Blackcompe is offline
Junior Member
 
Join Date: May 2008
Posts: 14
Default

use BETWEEN keyword
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 05-15-2008, 02:39 PM
General Cucombre General Cucombre is offline
Junior Member
 
Join Date: May 2008
Posts: 8
Default

It looks like your time_in field is DATETIME, which means that all values falling into May 8, will not match by original condition, because the engine casts 2008-05-08 to "2008-05-08 00:00:00" before it can compare the value to your time_in (i.e. midnight on that date).

You got to change your query to this:

SELECT * FROM timecard WHERE time_in >= '2008-05-03 00:00:00' AND time_in <= '2008-05-08 23:59:59'

Or, add 1 day to the upper limit, as you suggested yourself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql query: select second maximum? MentholTips MySQL 0 05-08-2008 04:52 PM
MySQL Query? Tina MySQL 2 05-06-2008 01:18 PM
MySQL Query | PHP Not Working.? DaddyJo MySQL 0 05-06-2008 01:05 PM
Perl date manipulation? Haley Perl 0 05-06-2008 12:30 PM
Help me to write a mySQL query . How I write? Jack J MySQL 0 05-06-2008 10:21 AM

Your Ad Here

All times are GMT. The time now is 03:32 PM.