For complete dates:
-- Se seu campo for DATE:
SELECT * FROM tabela WHERE DATE(minhadata) = '2014-05-21';
-- Se seu campo for VARCHAR:
SELECT * FROM tabela WHERE LEFT(minhadata,10) = '2014/05/21';
To year only:
-- Se o campo for DATE:
SELECT * FROM tabela WHERE YEAR(minhadata) = '2014';
-- Se o campo for VARCHAR:
SELECT * FROM tabela WHERE LEFT(minhadata,4) = '2014';
For month only:
-- Se o campo for DATE:
SELECT * FROM tabela WHERE MONTH(minhadata) = '05';
-- Se o campo for VARCHAR:
SELECT * FROM tabela WHERE SUBSTR(minhadata, 6, 2) = '05';
For day only::
-- Se o campo for DATE:
SELECT * FROM tabela WHERE DAY(minhadata) = '23';
-- Se o campo for VARCHAR:
SELECT * FROM tabela WHERE SUBSTR(minhadata, 9, 2) = '23';
Combining the above possibilities
Here’s an example of how to get the records for the 17th of every month of 2013:
-- Se o campo for DATE:
SELECT * FROM tabela WHERE
YEAR(minhadata) = '2013' AND
DAY(minhadata) = '17';
-- Se o campo for VARCHAR:
SELECT * FROM tabela WHERE
LEFT(minhadata,4) = '2013' AND
SUBSTR(minhadata, 9, 2) = '17';
Note that I am considering the date VARCHAR
in format AAAA/MM/DD
.
For other formats, adjust the SUBSTR(campo,posicaoinicial,quantidade)
accordingly.
I put an answer that does not use regex, in fact I imagine that regex would not bring any benefit in this case.
– Bacco