Suppose you need some condition for get next date like
1. Current date is 13-02-2018 , in this case you need to get immediate date like if you select date is 10 then output will be 10-03-2018 cause select date already passed
2. if you select 15 then output will be 15-02-2018 cause this date future date
3. final if you select previous date of current month then output will be next month same date and if you select future date of current month then output will be same month.

This is simple php code which give you correct result

$input = 12;
$day = date("d");

if ($input > $day){
    $date = date("Y-m-"). str_pad($input,2,"0", STR_PAD_LEFT);
}else{

    $date = date("Y-m-",strtotime("+1 month")). str_pad($input,2,"0", STR_PAD_LEFT);
}

echo $date;

If you run this code then output is :

then result is : 2018-03-12 cause you select date which already passed
if you set $input = 15; then result is: 2018-02-15 cause you select future date which not pass