After I have validated the receipt against the App Store from my PHP server, the App Store sends me back a JSON response with
"status" : 0
"receipt" : ( .... )
One of the receipt items is "purchase_date" which contains the following string (example) "2010-02-09 19:17:04 Etc/GMT"
I'm trying to establish a subscription service and would like to add 3 months to this date and then write that expiry date into a MySQL table.
Is there a string-to-date type function in PHP that can allow me to achieve the adding of 3 months?
I have found this example which looks like it adds 1 month to a date:
$date 开发者_如何学JAVA= date("Y-m-d");// current date
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
But I'm not sure how I can turn the string passed by the App Store into a PHP recognised date.
You have already done it, you just added one step too many.
$purchase_date = "2010-02-09 19:17:04";
$purchase_date_timestamp = strtotime($purchase_date);
$purchase_date_3months = strtotime("+3 months", $purchase_date_timestamp);
echo "Purchase date + 3months = ".date("Y-m-d h:i:s", $purchase_date_3months);
this depends on strtotime
recoginzing your time string - try it out first. But usually, strtotime can recognize any properly formatted anglo-american date/time string. If in doubt, check the manual.
Don't treat time as a scalar value - It's much more complex than that. I would suggest that you push this logic into your database, provided that you use a one for storing data? Alternatively, recent versions of PHP has a datetime object, which can be used.
精彩评论