If a field contains date values with varchar data type, the following is the query to get year from that field

mysql> select identification_date from table1;

+———————+
| identification_date |
+———————+
| 11/05/2013          |
| 12/04/2012          |
| 02/06/2011          |
| 11/04/2012          |
| 11/04/2010          |
+———————+
5 rows in set (0.00 sec)

mysql > select YEAR(STR_TO_DATE(identification_date,’%d/%m/%Y’)) from table1;

+—————————————————+
| YEAR(STR_TO_DATE(identification_date,’%d/%m/%Y’)) |
+—————————————————+
|                                              2013 |
|                                              2012 |
|                                              2011 |
|                                              2012 |
|                                              2010 |
+—————————————————+
5 rows in set (0.03 sec)

Advertisements