Date calculation macro

I’m trying to calculate time in a custom macro, but as far as i can tell XWiki does only have $datetool as “org.apache.velocity.tools.generic.ComparisonDateTool” referenced?

Because this wont work:

#set($cal = $datetool.getCalendar())
#set($discard = $cal.add($cal.YEAR, 2))
$cal

Somehow this gives just the current time, and $cal.YEAR strangely gives 126 (?)

Is there any other way to get something like this working?

Thanks, raphael

Hi raphael,

A bit simply page with correct call Date Calculations

Remember, you have to format date with mask depending how do you prefer it to be displayed such

$datetool.format("yyyy-MM-dd", $cal.getTime())

Personally, I’d suggest to use Groovy because it provides more methods of date manipulation compare to Velocity