On 10/23/2010 10:45 PM, Eugen Colesnicov wrote: > > I checked this example and your script - it is not correct, because you > compare separately year, month and day of document with current date - year, > month and day-100. But if, for example now is 02 january, your script give > uncorrect result, becase I also should change year and month (and year), > then I want to get date BEFORE 100 days of 02 january. > > Need to make arithmetical operations with dates and these operations should > consider also possible transitions of month and year when day changed ... > In any case - thanks! > > I found the answer - need to use special velocity object $datetool
You can use the jodatime plugin, which makes it easier to work with dates. See https://svn.xwiki.org/svnroot/xwiki/platform/xwiki-plugins/trunk/jodatime/ Accessed with $xwiki.jodatime Also, you shouldn't use computed date segments as constants inside a query, but do a parameterized query and compare dates. Schematic example: $xwiki.searchDocuments(", DateProperty someDateProp where someDateProp.value > ?", [$computedStartDate]) > Example: > #set ($d = 5) - days interval which I need > #set ($ms = $d * 24 * 60 * 60 * 1000) - Calculating internal in > Milliseconds > > #set ($calendar = $datetool.getCalendar()) > #set ($currentTime = $calendar.getTimeInMillis()) > #set ($targetTime = $currentTime - $ms) > #set ($void = $calendar.setTimeInMillis($targetTime)) > #set ($targetDate = $calendar.getTime()) > #set ($targetYear = $datetool.getYear($targetDate)) :get year of > a date = currentdate - 5 days > #set ($targetMonth = $datetool.getMonth($targetDate) + 1) :get month of a > date = currentdate - 5 days > #set ($targetDay = $datetool.getDay($targetDate)) :get day of > a date = currentdate - 5 days > > and after this, in a hql searching, I can compare this year, month, and day > with documents year, month and day ... > -- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
