0

I'm trying to make a subscription based system, once a person registers he/she can choose a package for 1/3/6 months and pay for it, once the payment is successful, a date stamp is added, this date stamp is based on the package i.e if the package is purchased today it will be of the same day 3 months ahead or 1 month or whatever.

I'm having problems creating a function that solves this.

  • What if they buy a 3 month subscription on 31st January 2015? – Mark Baker Jul 24 '15 at 07:16
  • What problems are you actually having? Where is the code for your problem function? – Mark Baker Jul 24 '15 at 07:17
  • Just look at this question: http://stackoverflow.com/questions/2305902/in-php-how-do-i-add-3-months-to-the-purchase-date-retrieved-from-the-iphone-ina – OSDM Jul 24 '15 at 07:17
  • http://php.net/manual/en/function.strtotime.php – Loko Jul 24 '15 at 07:17
  • possible duplicate of [Adding months to a existing date?](http://stackoverflow.com/questions/3812929/adding-months-to-a-existing-date) – Alfwed Jul 24 '15 at 08:31

3 Answers3

0

Let's say your package subscription is for 3 months from now. You can get that date like this:

echo date('Y-m-d H:i:s', strtotime('+3 months', time()));
Raja Amer Khan
  • 1,489
  • 10
  • 31
0

This worked for me, thanks everyone!

$dateNow = new DateTime();
$dateAhead = $dateNow->add(DateInterval::createFromDateString('3 months'));
print $dateAhead->format('Y-m-d');
Vinie
  • 2,983
  • 1
  • 18
  • 29
0
/**
 * @param $month your package subscription is for $month months from now
 * @param string $format
 * @return bool|string
 */
function subscription($month, $format = 'Y-m-d H:i:s')
{
    return date($format, strtotime('+' . $month . ' months', time()));
}
Yanlong He
  • 14
  • 2