Gremlin convert properties to date and calculate diff in days

Viewed 306

In a graph database, imagine I have a vertex with 2 properties: createDate and modifiedDate, both of them of type string with values like: 2015-12-22 04:35:36.0

Is there a way to calculate the difference in days between the modifiedDate and createDate?

This query will be running on AWS Neptune.

Thank you

1 Answers

Using TinkerGraph to demonstrate here is a way to do what you need using Epoch time.

gremlin> t1 = System.currentTimeMillis()
==>1582730843623
gremlin> g.addV('T1').property('time',t1)
==>v[60867]
gremlin> t2 = System.currentTimeMillis()
==>1582730863462
gremlin> g.addV('T2').property('time',t2)
==>v[60869]

gremlin> g.V().hasLabel('T1','T2').group().by(label).by(values('time').unfold()).math('T2 - T1')
==>19839.0
Related