title: Php: How can I get the same date of the following months, quarterly and semi-annually
body: <p>I'm this situation where users can choose to be billed either every month, quarter or semi-annual on one specific date the choose in a billing cycle. I'm using Laravel PHP framework.</p>
  
  <p>Eg. Monthly - 5 May 2016, 5 June 2016, 5 July 2016, etc.
  Billed on 5 on every month
  Eg. Quarterly - 10 Jan 2016, 10 March 2016, 10 June 2016 etc...
  Billed on 10 after every three months
  Eg. Semi-Annually - 13 Apr 2016, 13 Sept 016
  Billed on 13 after every six months.</p>
  
  <p>The goal here is to get the same date on the every month the user choose to be billed, but in a month, quarterly or semi-annually.</p>
  
  <p>This is my code after I play with @Rishi methode for some time</p>
  
  <pre><code>public function as_you_go($pay_as_you_go,$grand_total,$payment_date,$policy_id)
  {
      $policy = $this-&gt;findorFail($policy_id);
      if($pay_as_you_go == 'Semi-Annually'){
          $payments_no = 2;
          $installment_amount = $grand_total/$payments_no;
          $month_gap = 6;
          $add_month = '+6 month';
      }elseif($pay_as_you_go == 'Quarterly'){
          $payments_no = 4;
          $installment_amount = $grand_total/$payments_no;
          $month_gap = 3;
          $add_month = '+3 month';
      }elseif($pay_as_you_go == 'Monthly'){
          $payments_no = 12;
          $installment_amount = $grand_total/$payments_no;
          $month_gap = 1;
          $add_month = '+1 month';
      }
  
      // Pay as you go calculations
      for ($x = 0; $x &lt; $payments_no; $x++) {
          //$add_month = '+'.$x.' month';
          $installment = new \App\Installment;
          $installment-&gt;amount = $installment_amount;
  
  
          if(\App\Installment::wherePayableType('App\Policy')-&gt;wherePayableId($policy-&gt;id)-&gt;first()){
  
              $payment = \App\Installment::wherePayableType('App\Policy')-&gt;wherePayableId($policy-&gt;id)-&gt;orderBy('id', 'desc')-&gt;first();
              $date = $payment-&gt;payment_date-&gt;format('Y-m-d');
              $installment-&gt;payment_date = date('Y-m-d',strtotime($date.$add_month));
          }else{
              $installment-&gt;payment_date = $payment_date;
          }
          $installment-&gt;is_payed = 'No';
          $policy-&gt;installments()-&gt;save($installment);
      }
  
  }
  </code></pre>
  
  <p>This is my function I wanted to generates dates according to user's date of choice based on semi-annual, quarterly and monthly payment gap.</p>