0

I'm having an issue getting my code to add a day depending on the result of a drop down, the drop down values are 1-6 and the held in a variable $changeDate and depending on each adds the corresponding amount of days onto my current date. However, for some reason the output day isn't working correctly.

$currentDate = "01/02/2003";

if($changeDate == "1"){
    $newDate = date('d/m/Y', strtotime($currentDate.' + 1 days'));
}
elseif($changeDate == "2"){
    $newDate = date('d/m/Y', strtotime($currentDate.' + 2 days'));
}
elseif($changeDate == "3"){
    $newDate = date('d/m/Y', strtotime($currentDate.' + 3 days'));
}
elseif($changeDate == "4"){
    $newDate = date('d/m/Y', strtotime($currentDate.' + 4 days'));
}
elseif($changeDate == "5"){
    $newDate = date('d/m/Y', strtotime($currentDate.' + 5 days'));
}
elseif($changeDate == "6"){
    $newDate = date('d/m/Y', strtotime($currentDate.' + 6 days'));
}

echo $newDate;

Results of $changeDate == 1: 03/01/2003

Results should be: 02/02/2003

Results of $changeDate == 2: 04/01/2003

Results should be: 03/02/2003

Results of $changeDate == 3: 05/01/2003

Results should be: 04/02/2003

Results of $changeDate == 4: 06/01/2003

Results should be: 05/02/2003

Results of $changeDate == 5: 07/01/2003

Results should be: 06/02/2003

Results of $changeDate == 6: 08/01/2003

Results should be: 07/02/2003

ben topper
  • 13
  • 1
  • 4

0 Answers0