The main problem is, that I have stored in database datetime , not the date (what I need). Ok never mind.
I have thousands of reports stored each day.
I need to LEFT by 10 my datetime_view (to cut the time) and everything’s fine. Except this. I’m trying to figure out why do I have to put in the condition + one day from the future? Otherwise it won’t search what I want.
SELECT
LEFT(datetime_view,10),
count(type)
FROM reports
WHERE
type IN (1,2,5)
AND
datetime_view>='2012-10-28'
AND
datetime_view<='2012-11-04'
group by LEFT(datetime_view,10);
You can see I must search from the future. Why??
It gives me an output from 28.10 to 3.11 ….
don’t use string operations on date/time values. MySQL has a huge set of functions for date/time manipulation. Try
instead, which will extract only the date portion of the datetime field. Your string operation is not y10k compliant. Using the date() function is.
As for your
plus one day, consider how the comparisons are done: A plain date value, when used in date/time comparisons, has an implicit00:00:00time value attached to it, e.g. all dates have a time of “midnight”.