S.M_Emamian S.M_Emamian - 1 year ago 73
MySQL Question

using <= or >= in timestamp field in mysql

I would like to select all records before


where date < 2014-03-22 // what I need

but below code doesn't see 2013 year's records :

SELECT * FROM `tractions` WHERE YEAR(date) <= 2014 AND MONTH(date) <= 3 and DAY(date) <= 22 and succ = 1

Answer Source

Is there anything wrong with:

SELECT * FROM tractions
WHERE date < '2014-03-22'    -- place the date, correctly formatted, in quotes

Since this comparison doesn't use any functions, it will also allow you to use any indices setup on the date column.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download