cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

DateTime Format

How can I save and retrieve DateTime along with timezone in neo4j while creating a new node?

CREATE (n:Person {name: "John", age: 24, dob: datetime("what should be the format here")});

I am sending the format "2018-12-26T22:10:15.120+05:30" from the client.

Also how to retrieve this DateTime object as a string in any format?

1 ACCEPTED SOLUTION

You should be able to do something like this:

CREATE(n:Person {name:"John", age: 24, dob: datetime("2018-12-26T22:10:15.120+05:30")})

That'll create a datetime object in neo4j. To access the values you should be able to something like this:

MATCH(n:Person) WITH n.dob as date RETURN date.year, date.month, date.day, date.hour, date.second

Depending on your usage, in my case the Go driver that I'm using returns it as a time language in Go, the case might be similar for you. If not there is an apoc function.

MATCH(n:Person) WITH n.dob as date RETURN apoc.date.format(date.epochSeconds, 's', 'MMM d yyyy') AS dateOfBirth

View solution in original post

2 REPLIES 2

You should be able to do something like this:

CREATE(n:Person {name:"John", age: 24, dob: datetime("2018-12-26T22:10:15.120+05:30")})

That'll create a datetime object in neo4j. To access the values you should be able to something like this:

MATCH(n:Person) WITH n.dob as date RETURN date.year, date.month, date.day, date.hour, date.second

Depending on your usage, in my case the Go driver that I'm using returns it as a time language in Go, the case might be similar for you. If not there is an apoc function.

MATCH(n:Person) WITH n.dob as date RETURN apoc.date.format(date.epochSeconds, 's', 'MMM d yyyy') AS dateOfBirth

Thank you so much, that worked for me.