Reputation: 9646
How to set current DateTime in the gremlin console?
I need to add an audit field created_on
with current_timestamp
as default value
Eg:
g.addV('student').property('name', 'Thirumal').property('created_on', datetime())
In, the above query, I am getting an error on datetime()
. What is the syntax to add default date time?
Upvotes: 1
Views: 656
Reputation: 14391
In the Gremlin Console, you can use new Date()
if you do not have a version that supports datetime()
. Note that datetime()
was recently added to Gremlin so you may not have the version that contains it yet. I believe it was added in the 3.5.2 release. Also please see this discussion
Without datetime()
you can still do
gremlin> g.addV('test').property('date', new Date())
==>v[61287]
gremlin> g.V(61287).valueMap()
==>[date:[Thu Feb 10 10:02:18 CST 2022]]
UPDATED based on comments:
If you are using Amazon Neptune, the database provides its own version of the datetime
function that expects an ISO 8601 compliant date string. So you can do something like this:
g.addV('test').property('date', datetime('2022-02-10'))
If you are using Neptune's Jupyter notebooks, to set the current date, you can create a date in a cell above (using Python) of the form
my_date = # some date calculation that yields an ISO string.
or, more concretely:
import datetime
d=datetime.datetime.now()
my_date = d.strftime('%Y-%m-%d')
and inject that string like this:
g.addV('test').property('date', datetime('${my_date}'))
Upvotes: 2