Here is a simplified example of code that I want to run under BOLT and that I was able to execute uner py2neo
timeCreated = datetime.datetime(year=2016, month=6, day=15, hour=23)
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "password"))
session = driver.session()
stmt = 'CREATE (y:Year) SET y.timeCreated = {time}'
session.run(stmt, {"time": timeCreated})
timeCreated is python datetime object. I get an error message that a datetime object cannot be used:
ValueError: Values of type <class 'datetime.datetime'> are not supported).
Is there a workaround for this? Will it be supported in the future? I'd like to use the BOLT driver and reduce the dependency on py2Neo but it seems that not all functionalities can be transferred yet.
Neo4j doesn't natively support datetimes, and I believe py2neo silently converted datetimes into strings in previous versions.
My workaround has been to call the .isoformat()
method on datetime
objects to insert them into databases as strings.