比较日期时为什么Diff总是积极的?

I'm using this code to return the number of days between two dates - today, and a date from the database:

$now = new DateTime("now");
$date2 = new DateTime($row[$CalendarField]);
$interval = $now->diff($date2);
$age = $interval->days;

How can I alter the code so that $age returns a negative value for dates in the past?

Look at the invert property in DateInterval class.
http://php.net/manual/pl/class.dateinterval.php

You can also use characters r and R in DateInterval::format method.
http://php.net/manual/pl/dateinterval.format.php

Try to replace your code with

    $now = new DateTime("now");
    $date2 = new DateTime($row[$CalendarField]);
    $interval = $now->diff($date2);
    $age = $interval->format('%r%a');