I have saved the dates of a user\'s registration as a datetime, so that\'s for instance 2011-12-06 10:45:36. I have run this query and I expected this item
Have you tried before and after rather than >= and <=? Also, is this a date or a timestamp?
Another alternative is to use DATE()
function on the left hand operand as shown below
SELECT users.* FROM users WHERE DATE(created_at) BETWEEN '2011-12-01' AND '2011-12-06'
Maybe use in between better. It worked for me to get range then filter it
SELECT users.* FROM users WHERE created_at BETWEEN '2011-12-01' AND '2011-12-07';
You can use MySQL DATE
function like below
For instance, if you want results between 2017-09-05 till 2017-09-09
SELECT DATE(timestamp_field) as date FROM stocks_annc WHERE DATE(timestamp_field) >= '2017-09-05' AND DATE(timestamp_field) <= '2017-09-09'
Make sure to wrap the dates within single quotation ''
Hope this helps.
Searching for created_at <= '2011-12-06'
will search for any records that where created at or before midnight on 2011-12-06
. You want to search for created_at < '2011-12-07'
.