How to handle dates in neo4j

后端 未结 4 1146
眼角桃花
眼角桃花 2020-12-15 20:28

I\'m an historian of medieval history and I\'m trying to code networks between kings, dukes, popes etc. over a period of time of about 50 years (from 1220 to 1270) in mediev

4条回答
  •  被撕碎了的回忆
    2020-12-15 21:01

    The common way to deal with dates in Neo4j is storing them either as a string representation or as millis since epoch (aka msec passed since Jan 01 1970).

    The first approach makes the graph more easily readable the latter allows you to do math e.g. calculate deltas.

    In your case I'd store two properties called validFrom and validTo on the relationships. You queries need to make sure you're looking for the correct time interval.

    E.g. to find the king(s) in charge of France from Jan 01 1220 to Dec 31st 1221 you do:

    MATCH (c:Country{name:'France'})-[r:HAS_KING]->(king)
    WHERE r.validFrom >= -23667123600000 and r.validTo <=-23604051600000
    RETURN king, r.validFrom, r.validTo
    

    addendum

    Since Neo4j 3.0 there's the APOC library which provides couple of functions for converting timestamps to/from human readable date strings.

提交回复
热议问题