Filing Birthday Anniversaries

3

I'm trying to filter out the day's birthdays, but I can not. I can only put the date of birth exactly; to be sure you had to filter the dates of birth the same day and month (discarding the year of birth)

SELECT NomeCompleto, Telefone FROM tblcliente WHERE DataNascimento = '1995-12-08'
    
asked by anonymous 20.11.2017 / 14:45

3 answers

2

You can do this as follows:

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

In this case, using MONTH , we can filter by month. In the same way, we can then do using YEAR , to filter by year, as shown below:

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

You can do the following to get the expected result:

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

For search and knowledge purposes, you can also filter by period, for reports, as follows:

SELECT NomeCompleto, Telefone FROM tblcliente WHERE DataNascimento BETWEEN '2000-01-01' AND '2020-12-31'
    
20.11.2017 / 14:48
3

Another option would be as follows:

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 it with the current date, thus returning only those with the same day and independent month of the year.

Note: I did in postgresql this query but it is quiet to change to mysql

Here shows how to use extract in MySQL

In your case, believe that something like this looks 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())
    
20.11.2017 / 14:56
1

You can fetch all records that are on a given day using the DAY () and month using the 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 fetch all records on a particular date regardless 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

    
20.11.2017 / 15:07