1
Good day, late or night
I have the following question: How can I take the birth date of a registered user and make a calculation to know his age today?
If the user is under 18 years for example, he will not be able to access the purchase page of a certain product (regardless of age the user needs to be logged in to be able to access the purchase page).
The code at the moment is like this:
<?php
date_default_timezone_set('America/Sao_Paulo'); // Hora oficial do Brasil.
include_once("../../pagina_de_cadastro/conecta_banco.php"); //Faz a conexao e seleciona o BD
$select = "SELECT data_nasc FROM usuarios"; // Pegamos o conteudo do banco.
$data_inicial = DateTime::createFromFormat('y/m/d', 'data_nasc'); //A data do banco deve esta no formato dia/mês/ano
$data_final = date('y/m/d'); // Salva o timestamp atual numa variável
$diferenca = $data_final - $data_inicial;
echo $diferenca;
if ($diferenca < 18) {
echo '<p style="font-size:300px"> IDADE INSUFICIENTE </p>';
}
@fernandosavio believe that the fact that the language is different is not characterized as duplicate, no?
– Tuyoshi Vinicius
My fault, as has the JS tag ended up precipitating me.
– fernandosavio
The duplicate is of this.
– fernandosavio