Select all persons who have birthday date higher than 2000

Asked

Viewed 76 times

1

I’m trying to select all the people who have a birthday date higher than 2000 That date has to be accurately taking into account the day and month, and not simply decreasing the year!

inserir a descrição da imagem aqui

2 answers

4


How to do

SELECT *
FROM usuarios
WHERE YEAR(nascimento) > 2000

How to filter parts of a date

Use the functions YEAR, MONTH, DAY who take YEAR, MONTH, DAY of date field:

SELECT * FROM usuarios
WHERE YEAR(nascimento) = '2000' AND MONTH(nascimento) = '07' AND DAY(nascimento) = '07'

If it has more than 1 value:

SELECT * FROM usuarios
WHERE YEAR(nascimento) = '2018' AND MONTH(nascimento) IN ('07','09','11')

In a sequential interval:

SELECT * FROM usuarios
WHERE YEAR(nascimento) = '2018' AND MONTH(nascimento) BETWEEN '05' AND '12'

Functioning in the db-fiddle

as our friend posted in the comments.


Useful links

Mysql - Date and Time Functions

  • 1

    I made a db-fiddle if you want to add to the answer.

  • @fernandosavio opa claro!

0

You can do it like this

SELECT * FROM usuarios WHERE nascimento >= 2000
  • So it doesn’t work because it would have to have the field again after the OR to make the comparison. And if it were to include also 2000, would only put >= 2000.

Browser other questions tagged

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