javadateorientdbjbake

How to get only year from a date stored in OrientDB


I'm working on JBake, and would like to get the year part of the date at which a document was stored.

I know I can get the date by doing

SELECT date FROM post

And OrientDB will return me a java.util.Date.

I know I can also add the year as another field, but I find this data duplication unsatistfying.

So, is it possible to store the date, and to to have the year extracted through some kind of SQL "function" ?

Typically I would love to do

SELECT date, {date.getYear()} FROM post

Solution

  • You could use the format() function using the SimpleDateFormat syntax:

    select date.format('YYYY') from post