Filtering data based on datetime

Is there an option of filtering data using views based on current datetime
For ex. I’ve many JSON Document each of these document contains a key:value as

I would like to filter those documents whose Starttime is less than current time. Is there a way I can achieve this using view.


Couchbase has a great builtin datetime into array function for the mapper

from here you can put the key into start and end range in your view query.


Suppose you have a document like this one:

{ "type": "product", "date": "2013-08-25T13:41:13.163+01:00" }

If you want to do some queries on the date, you need to create a view to index the date, and use a compound key:

function (doc, meta) { emit( dateToArray(; }

This will generate an index based on the date that is like the following:


So if you want to get all the document id where the date is “before” August 25 , you have do to this query"



Thanks !!


Thanks for the explanation of the datetime queries. I am still a bit confused about writing queries. My timezone is -4:00.

Here is a sample date in a document:

Output of emit( dateToArray(; is [ 2014, 10, 23, 21, 6, 38 ]

Note 21 in the output where it has been converted to GMT time. If I want to query all data earlier than 2014-10-23T17:06:38.1980646-04:00, do I need to write query with GMT converted time ?

Do I write this …

?startkey= [ 2014, 10, 23, 21, 6, 38 ]&descending=true

or this

[ 2014, 10, 23, 17, 6, 38 ]