Filtar Birthday of the day

Asked

Viewed 1,115 times

3

I’m trying to filter out the birthday kids for the day, but I’m not making it. I can only put exactly the date of birth; to make it right I needed to filter the dates of birth of the same day and month (discarding the year of birth)

SELECT NomeCompleto, Telefone FROM tblcliente WHERE DataNascimento = '1995-12-08'

3 answers

2

Another option would be the following:

SELECT data FROM public.estoque where extract (month from data) = extract (month from CURRENT_DATE) and  extract (day from data) = extract (day from CURRENT_DATE)

Where you extract the month and day from your table and compare with the current date, thus returning only those with the same day and month independent of the year.

Observing: I did in postgresql this query but it is easy to change to mysql

Here shows how to use the extract in Mysql

In your case, believe it to look something like this:

SELECT NomeCompleto, Telefone FROM tblcliente WHERE extract(month from DataNascimento) = extract(month from NOW()) and extract(day from DataNascimento) = extract(day from NOW())

1


You can do it this way:

SELECT NomeCompleto, Telefone FROM tblcliente WHERE MONTH(DataNascimento) = 5

In this case, using MONTH, We can filter by month. Similarly, we can then do it using YEAR, to filter by year, as shown below:

SELECT NomeCompleto, Telefone FROM tblcliente WHERE YEAR(DataNascimento) = '2017'

You can do as follows, to get the expected result:

SELECT NomeCompleto, Telefone FROM tblcliente WHERE DAY(DataNascimento) = '02' AND MONTH(DataNascimento) = '5'

For research and knowledge purposes, you can also filter by period, in case of reports, as follows:

SELECT NomeCompleto, Telefone FROM tblcliente WHERE DataNascimento BETWEEN '2000-01-01' AND '2020-12-31'

1

You can search all records that are from a given day using the function DAY() and month using function MONTH() as follows:

SELECT * FROM tblcliente 
WHERE MONTH(DataNascimento) = 12 AND DAY(DataNascimento) = 8

Sqlfiddle - Example working online

Another way to do the search is to search all the records of a certain date independent of your time, using Date_add():

SELECT * 
FROM tblcliente 
WHERE DataNascimento >= '1993/08/04'
AND DataNascimento < Date_Add('1993/08/04',INTERVAL 1 DAY)

Sqlfiddle - Example working online

Browser other questions tagged

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