# Tutorial :Solr fetching date ranges

### Question:

Well, i'm coding some methods for returning solr docs that mach a interval date range. Docs stored date fields with ISO 8601 format.

Any idea?

thx

### Solution:1

Check in the SOLR wiki for some docs and examples:

timestamp:[* TO NOW]

createdate:[1976-03-06T23:59:59.999Z TO *]

createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]

pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]

createdate:[1976-03-06T23:59:59.999Z TO 1976-03-06T23:59:59.999Z+1YEAR]

createdate:[1976-03-06T23:59:59.999Z/YEAR TO 1976-03-06T23:59:59.999Z]

Hope this helps, David.

### Solution:2

Here you would find more details about range queries

A few exampled

``1. Exact Matching: q= modify_date:"2012-07-06T9:23:43Z"  2. Less than: q= modify_date:{* TO 2012-07-06T9:23:43Z }   3. More than: q= modify_date:{ 2012-07-06T9:23:43Z TO *}  4. Less or equal than: modify_date:[* TO 2012-07-06T9:23:43Z]   5. More or equal than: modify_date:[ 2012-07-06T9:23:43Z TO *]  ``

Square brackets [ ] denote an inclusive range query that matches values including the upper and lower bound.

Curly brackets { } denote an exclusive range query that matches values between the upper and lower bounds, but excluding the upper and lower bounds themselves.

### Solution:3

Suppose your field in Schema is as Modified_Date then you can apply following Range Queries:

``Modified_Date:[2015-04-20T07:49:00Z TO *]  Modified_Date:[2015-04-20T07:49:00Z TO 2015-05-  20T07:33:00Z]  Modified_Date:[2015-04-20T07:49:00Z TO NOW]  Modified_Date:[NOW-7DAY/DAY TO NOW]  Modified_Date:"2015-05-27T10:04:00Z"  Modified_Date:NOW  Modified_Date:NOW/DAY  Modified_Date:NOW/HOUR  Modified_Date:NOW-1YEAR  Modified_Date:NOW-2YEARS  Modified_Date:NOW-3HOURS-30MINUTES  Modified_Date:"2008-07-04T13:45:04Z/DAY"  Modified_Date:[* TO NOW]  Modified_Date://DAY  Modified_Date://HOUR  Modified_Date:[ * 2015-04-20T07:49:00Z ]  Modified_Date:[2015-04-20T07:49:00Z *]  ``

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »