1

So I have the following sql query

 SELECT * FROM log WHERE Date > 2013-12-12 00:00:00 AND Date < 2014-02-08 00:00:00 LIMIT 10

Where the log table has a column Date in the format Y-m-d H:i:s

One entry in the database has a Date of 2014-02-06 21:48:10 which should be picked up by this query no? But it's not.

Is there anything I'm missing here?

Thanks

1
  • 1
    Are the Date columns of type DATETIME? Commented Feb 7, 2014 at 4:21

2 Answers 2

3

You forgot the quotes

SELECT * FROM log WHERE `Date` > '2013-12-12 00:00:00' AND `Date` < '2014-02-08 00:00:00' LIMIT 10
Sign up to request clarification or add additional context in comments.

6 Comments

Knew it would be something stupid like that, thank you
you could have used BETWEEN
@Nouphal.M Then that would be different to the OP's logic. BETWEEN would be Date >= '2013-12-12 00:00:00' AND Date <= '2014-02-08 00:00:00'. See the difference?
@Phil, yes thats true
I had originally used between but as it was not working I switched to > and < thinking that would solve the issue, which it did not as the issue was with the quotes. I will be switching back to between.
|
2

you miss the quotes

Do like this for Date Range Selection

SELECT * FROM log  WHERE `DATE` BETWEEN "2013-12-12" AND "2014-02-08" LIMIT 10;

1 Comment

Note; BETWEEN is not the same (it is inclusive)

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.