Search first name in mysql field before MYSQL space

Asked

Viewed 100 times

2

I have to look for a date in a mysql field, but the guys had put it to save like this "2016-02-21 14:02:01" I just need the date from there , as I can check on select the date I want comparing to that date?

3 answers

2

select date(nomedacoluna) from minhatabela

more details on mysql date()

2

Like the @rray already answered, you can make a select by formatting the field, but this can take some of the performance.

For a more performative solution, I recommend using a clause BETWEEN as follows:

SELECT * FROM tabela WHERE campo BETWEEN '2016-02-21 00:00:00' AND '2016-02-21 23:59:59'

1

Can convert a datetime column to date only using cast(). Or by 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'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.