1
Staff a customer has a field datnasc
of the kind varchar
in his database and now he wants to fetch the birthday of the month.
How can I do this when the values entered in this field are in this pattern:
dd/mm/aaaa = 16/03/2017
1
Staff a customer has a field datnasc
of the kind varchar
in his database and now he wants to fetch the birthday of the month.
How can I do this when the values entered in this field are in this pattern:
dd/mm/aaaa = 16/03/2017
3
You have to turn it into a date (str_to_date) and then check by the month (MONTH) that takes only the month of a certain date, although the correct one was to write this data in the format date
or datetime
at the bank, example:
select * from tabela where MONTH(str_to_date(data, '%d/%m/%Y'))=MONTH(CURRENT_DATE())
References:
@Miguel yes true, the amendment is made, thank you...
You are welcome, I will delete the comment. Good reply
0
Use the SUBSTR function to pick up only the users' birthday month. See:
<?php
$mes = "03"; // mês atual ou escolhido para exibir os aniversariantes
$sql = "SELECT * FROM USUARIOS WHERE SUBSTR('DATA_NASC', 3, 2) =".$mes;
$qry = $pdo->prepare($sql);
$qry->execute();
?>
In this case, given a date 16/03/2017(for example) the SUBSTR function will pick up the characters from the third position with size 2, ie position 3 and 4 where the month is.
Browser other questions tagged php mysql
You are not signed in. Login or sign up in order to post.
You want to make a select?
– Marconi
@Marconi yes I want to make a select showing all the records that in datnasc have the month /03/
– user50712
Is there an option for you to make a change to your customer’s database structure? Or could this have some impact on any application that’s using it? Well, if you can change the structure without problems, then use the link @Virgilionovic commented, otherwise his answer would also solve, don’t forget to accept it as a solution.
– Jedaias Rodrigues
Your field is recorded this way:
dd/mm/aaaa = 16/03/2017
with all letters and numbers?– viana