13

I am using Neo4j 2.0 version. Suppose, I have lot of records which have date as one of their fields and if we need to support lot of queries like count of records between two specific dates etc, I think that I may have tpo index all the records by Date field. Is this correct? Then., how do I do it. All nodes of the type "RECORD" need to be indexed dy date. How can I achieve this? Please note that Date is a not unique field. And how do I even store Date property in the records. Is Date supported in CYPHER or Neo4j. How do I sort the records by Date field?

Vineel
  • 1,630
  • 5
  • 26
  • 47

1 Answers1

20

Dates as values for properties are not directly supported. Depending on your usecase you typically store the millis since epoch (aka date.getTime()) in a long property or a string representation using a DateFormatter (when being in Java land).

The long representation is better suited if you intend to do any math operation with dates. String is better if you want your properties being human readable without any conversion.

When requiring indexes on dates the easiest approach would be storing millis since epoch and apply a schema index on this.

Blago
  • 4,697
  • 2
  • 34
  • 29
Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • Not sure about your client language, but in JVM world you can call `date.getTime()` and you get back the number of milliseconds passed since Jan 1st, 1970, see http://docs.oracle.com/javase/7/docs/api/java/util/Date.html#getTime(). That is a long value ready to be stored as a property value. – Stefan Armbruster Feb 08 '14 at 09:19
  • 2
    Just wondering, shouldn't it be "if you **do** want your properties being human readable without any conversion"? – sthzg Nov 28 '15 at 10:33
  • 3
    I would not want to permanently store a "human readable" format in the database, especially if the application accessing the database is a locale-based application. Different locales will have different date formats, which means it's better to store the actual date value (or long, in this case) and then format it in the correct locale format at runtime. – ADTC May 15 '16 at 11:49
  • neo4 3.4 can now handle dates and time, see https://stackoverflow.com/a/51175076/1305302 for an example – loopasam Jul 04 '18 at 13:41