You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Adam Harris <ah...@marketforce.com> on 2013/11/05 20:25:48 UTC

DateDiff

Hey All,

Using solr I want to get the difference between two dates, is this possible?
Something similar to
SELECT DateDiff(d, GetDate(), date_Field) as Diff FROM MyTable

Re: DateDiff

Posted by Aloke Ghoshal <al...@gmail.com>.
Hi Adam,

With FunctionQuery (http://wiki.apache.org/solr/FunctionQuery) & DateMath (
http://lucene.apache.org/solr/4_5_1/solr-core/org/apache/solr/util/DateMathParser.html)
- round to the day level, subtract & divide by milliseconds_in_a_day
(86400K).

?q=*floor*(*div*(*sub*(*ms*(NOW/DAY),*ms*(NOW-1YEAR/DAY)),86400000))
&wt=xml&defType=func
&fl=*,score

Replace 'NOW-1YEAR' with you 'date_Field' (should be a TrieDateField).

Regards,
Aloke


On Wed, Nov 6, 2013 at 12:55 AM, Adam Harris <ah...@marketforce.com>wrote:

> Hey All,
>
> Using solr I want to get the difference between two dates, is this
> possible?
> Something similar to
> SELECT DateDiff(d, GetDate(), date_Field) as Diff FROM MyTable
>



On Wed, Nov 6, 2013 at 12:55 AM, Adam Harris <ah...@marketforce.com>wrote:

> Hey All,
>
> Using solr I want to get the difference between two dates, is this
> possible?
> Something similar to
> SELECT DateDiff(d, GetDate(), date_Field) as Diff FROM MyTable
>