24

I am trying to pull records after a certain date using mysql query , the field type is date in my database and the query is

SELECT * FROM tickets WHERE created_on > 26-08-2011

But it is not working and also showing all before that date

Thanks

3 Answers 3

62

The date you are using is a string, so it needs to be placed inside quotes. Also, the format is the wrong way around:

SELECT * FROM tickets WHERE created_on > '2011-08-26'

For more information, see the MySQL docs. In particular, note the very first line:

The format of a DATE value is 'YYYY-MM-DD'. According to standard SQL, no other format is permitted.

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

Comments

1

The date is defined in yyyy-mm-dd, so you should use the date as 2011-08-26. Using a date in this format is ideal for sorting as the numbers are arranged as incremental pieces. You have to use quotes on string values, see the post of James Allardice.

Comments

0

Try using quotes on the date and write dates in yyyy-mm-dd format for best results. '2011-08-26'

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.