Possible Duplicate:
add one year to datetime with php
Paid Date: 2012-10-19 13:13:20
Term: 3
(three years)
I need to turn these two values into a DateTime
that I can then compare to todays date and find out if the subscription is coming up for renewal.
Not sure how to properly accomplish this...
I've tried:
$term = $row['term'];
$paid = $row['paid_date'];
$renew = strtotime("+$term years", $paid);
$today = strtotime('now');
But apparently in this situation, all dates are less than ...
If you have the paid date as a string:
if(strtotime("2012-10-19 13:13:20 +3 years") > time()) {
// expired
}
If you have paid date as a timestamp:
if(strtotime("+3 years", $paidDate) > time()) {
// expired
}
turn the date into a timestamp and compare it with todays timestamp; if the difference is more than 3 years in seconds the subscription is running out.
Convert paid + 3 years and today into unix timestmps, if the renewal date is less than today, the subscription has expired.
$renew = strtotime('+'. $term .' years', $paid);
$today = strtotime('now');
If ($renew < $today)
{
//subscription has run out
}
Assumes $term is an integer from a database and $paid is a datetime from a MySQL database converted to a unix timestamp (select unix_timestamp(paid) as paid from paidtable).