My documents contain the following fields:
"valid_from": "Mar 17 08:55:04 2011 GMT"
"valid_to": "Mar 16 08:55:04 2017 GMT"
My base query currently looks like this:
r.db('items').table('token')
How can I query to only retrieve/filter the documents between the current date-time (now) and the "valid_to" field? i.e. anything with a "valid_to" date that is less than the current date/time is considered expired.
Calculate the number of days between the "valid_from" and "valid_to" fields. i.e. Determine the validity period in days.
#1
So, basically you want all documents that still haven't expired? (
valid_to
) is in the future?In order to do that, you should definitely use RethinkDB time/date functions. In order to do though, you have to create a time instance with either
r.time
orr. ISO8601
. An example of this is:Once you've inserted/update the documents using these functions, you can query them using RethinkDB's time/date functions. I you want all documents where
valid_to
is in the future, you can do this:If you want to get all documents where
valid_to
is in the future andvalid_from
is in the past, you can do this:#2
If both these properties (
valid_to
andvalid_from
) are time/date objects, you can add adays
property to each document by doing the following:The Python Code