1

I want to query data in mysql. The problem is the column is datetime(dpost) and i will use a date in the where clause.

SELECT * FROM `uid1000_qposts` WHERE `dpost`="2011-12-06"

this query doesn't return any results. Is there any possible way I can query data using date against a datetime column?

thanks

4 Answers 4

2
SELECT * FROM `uid1000_qposts` WHERE date(`dpost`) = '2011-12-06'
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

SELECT * FROM `uid1000_qposts` WHERE DATE_FORMAT(dpost,'%Y-%m-%d')='2011-12-06'

Comments

1
WHERE dpost between "2011-12-06 00:00:00" and "2011-12-06 23:59:59"

Another possibilities is using

DATE_FORMAT(dpost,'%Y-%m-%d')="2011-12-06"

but is not recommended,
as it won't make use on any index (even there is)

Comments

1
SELECT * FROM `uid1000_qposts` WHERE date(`dpost`) = '2011-12-06'

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.