-1
I’m doing this code to compare the current date with the date I entered into the form, I used this logic to do this, but apparently it’s not working. What could be wrong?
<?php
$data = $_POST['data'];
$nData = getdate();
$dataAno = date('y',strtotime($data));
$dataMes = date('m',strtotime($data));
$dataDia = date('d',strtotime($data));
if($dataAno > $nData['year']){
echo "Essa data não passou ainda..";
}elseif ($dataAno == $nData['year']){
if($dataMes > $nData['mon']){
echo "Essa data não passou ainda..";
}elseif($dataMes == $nData['mon']){
if($dataDia > $nData['mday']){
echo "Essa data não passou ainda...";
}elseif($dataDia == $nData['mday']){
echo "Essa data é a data de hoje!!!";
}echo "Essa data ja passou";
}
}
?>
The form looks like this:
<html>
<form method="post" action="teste.php">
<label>Data:</label>
<input type="date" name="data"><br><br>
<button type="submit">Enviar</button>
</form>
and how the date of the form is coming?
– user60252
your script has only one error
$dataAno = date('y',strtotime($data));
withy
minusculo. solution see my answer.– user60252