I have to look for a date in a mysql field, but the guys had put it to save so "2016-02-21 14:02:01" I just need the date from there, how can I check on the select date I want to compare with that date?
I have to look for a date in a mysql field, but the guys had put it to save so "2016-02-21 14:02:01" I just need the date from there, how can I check on the select date I want to compare with that date?
select date(nomedacoluna) from minhatabela
More details on mysql date ()
As @rray has already replied, you can do a select formatting field, but this may take a little bit of performance.
For a more performative solution, I recommend using a BETWEEN
clause as follows:
SELECT * FROM tabela WHERE campo BETWEEN '2016-02-21 00:00:00' AND '2016-02-21 23:59:59'
You can convert a column of type datetime to date only using cast()
. Or formatting the date with date_format()
SELECT * FROM tabela WHERE CAST(campo as date) = '2016-02-21'
or
SELECT * FROM tabela WHERE date_format(campo,'%Y-%m-%d) = '2016-02-21'