Find first name in the mysql field before MYSQL space

2

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?

    
asked by anonymous 21.02.2017 / 18:03

3 answers

2

select date(nomedacoluna) from minhatabela

More details on mysql date ()

    
21.02.2017 / 18:07
2

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'
    
21.02.2017 / 18:27
1

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'
    
21.02.2017 / 18:13