0

I am trying to search for studentID within a date range. I only have one date in my database, therfore i only want the users to input one date, rather than having them input a start date and an end date for: WHERE timeStamp BETWEEN startDate AND endDate

So i am trying this...

SELECT * FROM scansTable
INNER JOIN registeredUsers ON scansTable.studentID = registeredUsers.id
INNER JOIN labSession ON scansTable.labSessionID = labSession.id
INNER JOIN staffTable ON labSession.lecturer = staffTable.id
INNER JOIN unitTable ON labSession.unit = unitTable.id
WHERE studentID = '10'
AND labSession.StartTimeStamp BETWEEN '2011 -05 -30'+00:00:00
AND '2011 -05 -30'+23:59:59;

But it is not returning anything when i know for sure there is a student of id 10 and that date range in the database

Am i doing the +00:00:00 wrong??

thanks

4 Answers 4

4

Remove the spaces and plus symbols:

BETWEEN '2011-05-30 00:00:00' AND '2011-05-30 23:59:59'

Sign up to request clarification or add additional context in comments.

Comments

2

It seems you are using something like '2011 -05 -30'+00:00:00, where you should use '2011-05-30 00:00:00' (and make corresponsing changes to the second condition), because TIMESTAMP format (I assume this field is in this format) is YYYY-MM-DD HH:MM:SS.

Did it help? If not, give use the definition of the table plus the example row (at least both timestamp columns).

EDIT:

If you wanted to concatenate, you should have used CONCAT() function (see MySQL's documentation). It would look like this:

CONCAT('2011-05-30',' 00:00:00')

or, more meaningfully:

CONCAT_WS(' ','2011-05-30','00:00:00')

Comments

2

If you haven't changed the default date format, remove the + signs and the extra spaces.

labSession.StartTimeStamp BETWEEN '2011-05-30 00:00:00' AND '2011-05-30 23:59:59';

Also, I don't know if it's a byproduct of the copy/paste, but MySQL won't even run the query as-is. The time portion of your timestamp needs to be within the quotes.

Comments

0

between might not include that lower bound as an =

i believe it does include the upper bound as =, this might differ depending on the database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.