I am trying to substract two dates in MonoDB using the aggreation framework.
My code looks like this:
$ops = array(
array('$project' => array("fieldMath" =>
array( '$subtract' => array( 'new ISODate()', 'new ISODate("last_interacted_date")' )),
)),
array('$match' => array('fieldMath' => array('$gte' => 2),
),
),
);
$object -> aggregate($ops);
The problem is I'm getting an error that I am trying to substract 2 string.
Fatal error: Uncaught exception 'MongoResultException' with message 'localhost:27017: cant $subtract aString from a String
new ISODate
and the last_interacted_date
are both ISODate
objects.
My goal is to subtract a 'last_did_something' date from the date today, and return results for all queries that are within 2 days.
What am I doing wrong and how I can subtract dates?