Find all records until this time - MySQL
All,
I have a column with values ranging in time i.e.
Sun, 22 May 2011 20:15:00
Fri, 20 May 2011 10:15:00
Thurs, 19 M开发者_运维技巧ay 2011 09:15:00
Fri, 20 May 2011 13:15:00
and suppose the date/time now is Fri, 20 May 2011 15:00:00
.
I want to only retrieve those records created today until this point i.e. until Fri, 20 May 2011 15:00:00
.
How can I do that?
I know CURTIME()
gives the time at this point, but how do I vary the difference from midnight 12am to current time?
SELECT *
FROM TABLE
WHERE datetimecolumn BETWEEN date(now()) AND CURRENT_TIMESTAMP()
You want to do something like this
Retrieve those records created today until this point i.e. until Fri, 20 May 2011 15:00:00
SELECT *
FROM TABLE
WHERE datetimecolumn >= date(now()) -- current date without the time
AND datetimecolumn <= '2011-05-20 15:00:00'
精彩评论