S.M_Emamian S.M_Emamian - 3 months ago 13
MySQL Question

using <= or >= in timestamp field in mysql

I would like to select all records before

2014-03-22
date:

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

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.