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.
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
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 ?