-1

I'm putting together a little subscriptions script in PHP which will calculate the expiration date based on todays date and time, but it's giving the result of 0000-00-00 00:00:00 (Datetime)

Here is my code:

$added = date("Y-m-d H:i:s");
$expiry = strtotime('+ 1 year', $added);

How can I get this to give me the result of:

$added  =  2016-07-30 17-18-33
$expiry =  2017-07-30 17-18-33

1 Answers1

0

You're mixing between getting a timestamp and formatting it. Both need to be done in order to get the output you desire:

$now = time();
$added = date("Y-m-d H-i-s", $now);
$expiry = date("Y-m-d H-i-s", strtotime('+ 1 year', $now));
Mureinik
  • 297,002
  • 52
  • 306
  • 350