-2
I would like to take the date the user entered as the basis for the information he will select. There will be 4 date options, but the conditions are: if the user selects a day that has already passed, he will send me the day with the following month. Exp.: Today 18/03/2019 he can choose between: day 5; day 10; day 15; day 20; if he chooses day 5, 5<18, sends me the date 05/04/2019; if he chooses day 20, 20>18, sends me the date 20/03/2019;
So far I’ve made this PHP, however it is returning 0 on the dates, I would like your help to find what may be going wrong.
<?php
$data = date('d/m/Y');
$dataS = explode("/", $data);
$dia = $dataS[0];
$mes = $dataS[1];
$ano = $dataS[2];
?>
<?php
if($dia > 5){
$mes = date('m',strtotime('+1month'));
$d5 = $mes;
}
elseif($dia <= 5){
$mes = $dataS[1];
$d5 = $mes;
}
?>
<?php
if($dia > 10){
$mes = date('m',strtotime('+1month'));
}
elseif($dia <= 10){
$mes = $dataS[1];
$d10 = $mes;
}
?>
<?php
if($dia > 15){
$mes = date('m',strtotime('+1month'));
}
elseif($dia <= 15){
$mes = $dataS[1];
$d15 = $mes;
}
?>
<?php
if($dia > 20){
$mes = date('m',strtotime('+1month'));
}
elseif($dia <= 20){
$mes = $dataS[1];
$d20 = $mes;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
</head>
Data hoje:<?php echo $data ?>;<br>Dia:<?php echo $data[0] ?>;<br>Mês:<?php echo $data[1] ?>;<br>Ano:<?php echo $data[2] ?>;<br>Dia 5:<?php echo $d5 ?>;<br>Dia 10:<?php echo $d10 ?>;<br>Dia 15<?php echo $d15 ?>;<br>Dia 20<?php echo $d20 ?>
<body>
</body>
</html>
$dia = $data[0]
, shouldn’t be$dataS[0]
in place of$data[0]
?– Woss
yes, I saw it, I corrected it, but the error still stands
– Pedro Castilho
I’ll update the post, for how this now.
– Pedro Castilho
now when I test it, it returns the date, but the 'explode' is not going correctly, it returns "1"; "8", "/". Instead of "18", "03", "2019".
– Pedro Castilho
The
explode
works yes: https://ideone.com/gPxyGx– hkotsubo
as you can see, I did msm way in what I showed in the question...
– Pedro Castilho