Reputation: 755
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.
Upvotes: 2
Views: 2113
Reputation: 712
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.
Upvotes: 6
Reputation: 174692
Node4j has no concept of dates or times as properties of objects; so I doubt there will be support for datetime
type. You should store the epoch value instead:
import calendar
import time
epoch = calendar.timegm(time.gmtime())
Upvotes: 0