How can i select all fields in mysql starting with “2012-02”?
What i’ve tried:
mysql> SELECT title,id FROM dle_post WHERE approve='1' AND date = '2012-02-13 21:35:00';
+-------------------------------------------------+----+
| title | id |
+-------------------------------------------------+----+
| test title | 7 |
+-------------------------------------------------+----+
mysql> SELECT title,id FROM dle_post WHERE approve='1' AND date='2012-02%';
Empty set, 2 warnings (0.00 sec)
mysql> SHOW WARNINGS;
+---------+------+-----------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------------------------+
| Warning | 1292 | Incorrect datetime value: '2012-02%' for column 'date' at row 1 |
| Warning | 1292 | Incorrect datetime value: '2012-02%' for column 'date' at row 1 |
+---------+------+-----------------------------------------------------------------+
Ideally, dates should be treated as dates, not as strings. This query should return all rows for February 2012 and it should outperform
LIKE %queries: