如何使用PHP计算截止日期?

I had a vaccines it has to give at 2months,4months and at 6months.I need to calculate based on the Date of Birth as

EX:if the DOB:18-03-2015 and in due date section it has to show for 2months date as 18-05-2015. After the date completed it has to update automatically and change it to 4 months date as 18-07-2015.

I tried but it has not worked and it has to check with present date also.

How to do this Please help me.

My code:

<?php

      $date=date_create("now");//present date
      $bdate=date_create($myDate);//Birthday date
      //echo date_format($bdate,'d-m-Y');
        if($date >= $bdate)
        {
            $hadueDate=$bdate->modify('+2 month');//due date
            echo date_format($hadueDate,"d-m-Y");
        }
        else
        {
            $bdate->modify('+4 months');
            echo date_format($bdate,'d-m-Y');
        }
?>

This piece of code may help you mate. Run this code.

echo "<b>Today's Date:</b>".$Currentdate=date("d F Y");//current date
$user_date = date("d F Y",strtotime("2015-08-21"));//date you get from database
if($Currentdate<=$user_date){
echo '<br><b>First Date :</b>'.$first_date = date("d F Y",strtotime('+2 month',strtotime($user_date)));//only if current date is less than user's date
}
else{
echo '<br><b>Second Date :</b>'.$second_date = date("d F Y",strtotime ( '+4 month' , strtotime ( $user_date ) )) ;//only if current date is more than user's date
}

Here is the output

when 2015-08-21 is used

Today's Date:20 August 2015
First Date :21 October 2015

when 2015-08-01 is used

Today's Date:20 August 2015
Second Date :01 December 2015

Cheers!!

If I understand your question correctly, the algorithm should be:

  1. Calculate first due date (dob+2months)
  2. If present date is higher than first due date, calculate and display second due date (dob+4months)
  3. Else display first due date

Its simple,

Follow these steps

-Compare current date and date you want to test.

-Display date with additional 2 month if this date is less than test date

else

-Display date with additional 4 month .

Thanks