Good morning, afternoon or evening
I have the following question: How can I get the date of birth of a registered user and make a calculation to know his age today?
If you are under 18, for example, you will not be able to access the purchase page for a certain product (regardless of age, the user must be logged in to access the purchase page).
The code at the moment looks 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>';
}