'Neo4j Rest API datetime data types

I am using neo4j REST API to create nodes and relationships. I refer following documentation.

https://neo4j.com/docs/http-api/3.5/actions/

The nodes that I am dealing with have dynamic properties. Therefore I am using following payload with parameters to create nodes.

{
  "statements" : [ {
    "statement" : "CREATE (n:Person $props)  RETURN n",
    "parameters" : {
      "props" : {
        "name" : "My Node",
        "dob" : "datetime('20211229T153000')",
        "age": 55,
        "awsome": true
      }
    }
  } ]
}

This is perfectly work with String, Integer, Boolean data types. However I need to use datetime data type for "dob" . If I use datetime function within double quotes (as in above example) neo4j treat it as string value and does not store as datatime data type. Is there a solution for this?



Solution 1:[1]

You cannot put non-literal values inside the json data (props). However, you can change your cypher statement (create) to update the node and set the dob to a datetime field. But first you need to convert that string into datetime.

{
  "statements" : [ {
    "statement" : "CREATE (n:Person $props) SET n.dob = datetime({epochSeconds:apoc.date.parse(replace('20211229T153000','T', ' '),'s', 'yyyyMMDD HHmmss')}) RETURN n",
    "parameters" : {
      "props" : {
        "name" : "My Node",
        "age": 55,
        "awsome": true
      }
    }
  } ]
}

I replace the char 'T' into space so that it can be parsed. Then convert it into epoch seconds so that datetime will convert it properly. I tested it in my local neo4j so it should also work for you.

Result: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jose_bacoy