PHP日期计算startdate是否超过18个月

I have a simple php function which lists the months in order from a preset start date to the current date as below:

$this_date=date('F Y', time());
$startdate="1 December 2012";

function printMonths($var)
{
    $start = strtotime($var);
    $now = strtotime("Now");
    while ($now > $start)
    {
            echo date("F Y n", $now);
            echo "|";
            $now = strtotime("-1 month", $now);
    }       
}

$return_months=printMonths($startdate);

What I need to do is find out if the start date is greater than 18 months from the present day and if so set a new start date from 18 months ago. (All data is erased from the database once it is exactly 19 months old). I have set up a variable $this_date but not sure of the correct syntax to compare this with $startdate.

Using PHP's DateTime objects allows you to get the difference in months between two dates quite easily. For example:

$start = new DateTime('1 December 2012');
$end = new DateTime('today');
$diff = $start->diff($end);

The $diff object will then hold all the data you'll need:

object(DateInterval)[3]
  public 'y' => int 0
  public 'm' => int 1
  public 'd' => int 16
  public 'h' => int 0
  public 'i' => int 0
  public 's' => int 0
  public 'invert' => int 0
  public 'days' => int 46

You can then either match $diff->y == 1 && $diff->m >= 6 or $diff->y > 1 or a certain amount of $diff->days to see if the data is "too old".

Update

If you want to list the "last 18 months" (starting from December 2012), you can use the DatePeriod class. For example:

$start = new DateTime('1 December 2012');
$today = new DateTime('today');
$interval = new DateInterval('P1M');
$range = new DatePeriod($start, $interval, $today);

foreach($range as $date) {
    $diff = $today->diff($date);
    if(($diff->y == 1 && $diff->m >= 6) || $diff->y > 1) {
        break; // Stop iterations if more than 18 months.
    }
    echo $date->format('F Y'); // Prints December 2012 and January 2013
}