-6

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 ...

Community
  • 1
  • 1
dcolumbus
  • 9,596
  • 26
  • 100
  • 165

3 Answers3

0

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.

clem
  • 3,345
  • 1
  • 22
  • 33
0

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).

SteB
  • 1,999
  • 4
  • 32
  • 57
0

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
}
Salman A
  • 262,204
  • 82
  • 430
  • 521