Trouble getting date diff

I’m having trouble working with dates. Here’s what is asked of me to do:
A content type has a Reviewed Date field. On index page, items reviewed in the last X days have to be marked (“New!”).

This is how I approached it:
Created two bindings on the snippet template. One reads current date ($tools.date.getSystemDate()), the other reads Reviewed date from item ($sys.item.getProperty(“rx:date_reviewed”)). The former returns java.util.date, the latter is jcr property. If I do $sys.item.getProperty(“rx:date_last_reviewed”).getDate() I get gregorian calendar type. My idea is to get “time” property for both (number of seconds from set date) so I can compare/subtract the two. I can get that from the current system date ($tools.date.getSystemDate().getTime()) but got nowhere with the calendar.

I am not a java expert and was wondering if someone can help me, or suggest different approach.

Thanks…

The latest Velocity Tools has a “Comparison Date Tool” which will do what you want.

http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ComparisonDateTool.html

You will, however, have to “upgrade” your Velocity tools installation as described in this thread http://forum.percussion.com/showthread.php?t=123

Dave

Dave,

We are still on version 6.0
Does it matter?

I have not tested it, but I don’t see why it won’t work.

Dave

Works like a charm. And yes, velocity-tools-view is good to go as well. Many thanks.

Giving back:
$tools.datecompare.difference($itemdate,$sysdate).getDays()

Actually, should I put this set of tools under “date” key in that xml config file?