Filtering data based on datetime

Hi,
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
Starttime:2013-08-25T13:41:13.163+01:00.

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

Thanks

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

http://www.couchbase.com/docs/couchbase-manual-2.1.0/couchbase-views-writing-utilityfuncs.html#couchbase-views-writing-utilityfuncs-datetoarray

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

http://www.couchbase.com/docs/couchbase-manual-2.1.0/couchbase-views-writing-querying-selection.html#couchbase-views-writing-querying-selection-partial

Hello,

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(doc.date)); }

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

[2013,8,25,12,41,13]

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

?startkey=[2013,8,25,23,59,59]&descending=true

Regards
Tug
@tgrall

Thanks !!

Hi,

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:
2014-10-23T17:06:38.1980646-04:00

Output of emit( dateToArray(doc.date)); 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 ]
Thanks