cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

How can we get timestamp from the given date and time?

takhims
Node Link

Hi all,

I am a newbie to neo4j and have been struggling in making a cypher. The scenerio is, i am working on a new feature which will enable users to create reminders for themselves. The user will choose date and time for the reminder along with some other information. What i am asked to do is, save the reminder node with one more property (i.e timestamp) so that it will be easy to sort reminders according to timestamp. But however, i am unable to figure out a way to convert the the combination of the provided date and time to a timestamp. Have gone through all the documentation, still no luck. Can anyone help here? Please let me know if i have missed anything.

 

3 REPLIES 3

glilienfield
Ninja
Ninja

You can use the datetime function. Here is an example from the docs that illustrates calling it. As shown, it takes a map of the date and time components. You can create a map from you user’s inputs. 

WITH datetime({
year: 1984, month: 11, day: 11,
hour: 12, minute: 31, second: 14, nanosecond: 645876123,
timezone: 'Europe/Stockholm'
}) AS d
RETURN d.year, d.quarter, d.month, d.week, d.weekYear, d.day, d.ordinalDay, d.dayOfWeek, d.dayOfQuarter

https://neo4j.com/docs/cypher-manual/current/syntax/temporal/

 

 

Hi, thanks for the quick reply. But i want to convert it in unix times stamp. Is there any way, we can combine the given date and time and then convert that combination in UNIX timestamp.
Is there any function for that? Like timestamp() function. 

You can extract the epoch time from a dateTime value using the epochMillis property of the dateTime value. Here is an example:

RETURN datetime('2015-06-24T12:50:35.556+0100').epochMillis AS epocTime