dateorientdbjbake

In orientDB, how to search entries for which date are in a given year?


In my OrientDB instance, entries have date property which is stored as a java.util.Date.

I would like to get all documents written on a given year. But I don't think writing

SELECT FROM posts WHERE date.format('yyyy')=2012

Is the best way to do. or is it ?


Solution

  • The given query is very inefficient, a full table scan will be performed. Best is to use (a possible index can be used):

    select from posts where date between '2012-01-01 00:00:00' and '2012-12-31 23:59:59'
    

    Assumption: date is of type Date(Time)