Page tree
Skip to end of metadata
Go to start of metadata

The DateDiff  field expression calculates the difference between two dates and stores the result in a new field.  For instance, the following examples compare a document's publication date to an arbitrary date, and then expose the difference as the value of a new field in the document.  

Comparisons can be made on any of the following scales (see here ).  Note that DAYOFMONTH, DAYOFWEEK, and DAYOFYEAR produce the same result, which is the number of days between the two dates.

  • DAYOFMONTH
  • DAYOFWEEK
  • DAYOFYEAR
  • HOUR
  • MINUTE
  • MONTH
  • QUARTER
  • SECOND
  • WEEK
  • YEAR

Example:

QueryRequest request = new QueryRequest("*:*)");
FieldExpression delta = new DateDiff(CalendarField.DAYOFYEAR,new StoredField("date"),"2014-06-10");
delta.setAlias("DATEDIFF");
request.addField(delta);
// ... (Perform Search)

REST Syntax:

DATEDIFF(FUNCTIONNAME,FIELDEXPRESSION,FIELDEXPRESSION) AS ALIAS

  • FUNCTIONNAME - any of the available date extraction functions listed above
  • FIELDEXPRESSION - Any field expression that evaluates to a date.
  • ALIAS - New field name for the result of the function.

Example:

&fields=DATEDIFF(DAYOFYEAR,date,"2014-06-10") as "DATEDIFF"
  • No labels