Harea Costicla Harea Costicla - 1 year ago 68
MySQL Question

Select based on date not work

I have this sql :

SELECT * FROM table WHERE `end` >= '2016-06-20 00:00:00' AND end <= '2016-06-26 00:00:00'

If for example end =
2016-06-26 19:00:00
the sql doesn't get this row and I don't understand why. Can you help me please ?
Normally should work correctly

Answer Source

You're comparing full dates & times. and 00:00:00 comes BEFORE 19:00:00, therefore your 19:00:00 value is outside the specified range.

if you want to include all times on a particular date, then compare only the date values, e.g.

WHERE date(end) BETWEEN '2016-06-20' AND '2016-06-26'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download