Date
We can use date() function to create instance of Date. In addition, you can call the static method on dates to return a time based on the start of the transaction, statement or realtime.
A date can be created in two ways, by passing valid ISO 8601 data type as a String and by giving map containing year, month and day.
return date('2018-09-01'); "2018-09-01" return date({ year: 2018, month: 9, day: 2 }); "2018-09-02"
Time
In neo4j Time values can be created using time() function. Similar to Date, time instant can be created by ISO 8601 string and map of hour, minute, second, millisecond and/or nanosecond values.
UNWIND [ time('10:30:50.1234'), time({ hour: 10, minute: 30, second: 45, millisecond: 123, nanosecond: 400000 }) ] AS time RETURN time.hour, time.minute, time.second, time.millisecond, time.nanosecond, time.timezone; time.hour time.minute time.second time.millisecond time.nanosecond time.timezone 10 30 50 123 123400000 "Z" 10 30 45 123 123400000 "Z"
DateTime
DateTime is combination of both a date and a time. This is basically constructed by using combination of date and time constructs as I mentioned in above examples.
UNWIND [ datetime('2018-09-30T07:20:30[Asia/Kolkata]'), datetime({ year: 2018, month: 9, day: 30, hour:07, minute: 20, second: 30, timezone: 'Asia/Kolkata' }) ] AS datetime RETURN datetime; "2018-09-30T07:20:30[Asia/Kolkata]" "2018-09-30T07:20:30[Asia/Kolkata]"
Local Dates and Times
Local Dates and Local Times are used to store data without specifying any extraneous data. So instances of LocalDateTime and LocalTime can be considered “local†in their context, which means delivery shipped at 10:00 in Delhi would be in GMT or BST without specifying the timezone.
RETURN localtime(), localdatetime(); localtime() localdatetime() "15:35:37.956000000" "2018-09-30T15:35:37.956000000"
Durations between dates
In neo4j we can calculate difference between dates by using the duration.between(start, end) function. Duration.between function compares two points in time and it returns instance of Duration.
WITH date() as now, duration('P90D') AS duration RETURN now, now + duration AS dayAfter90Days; now dayAfter90Days "2018-09-30" "2018-12-29"
Configuration Changes
We also have an additional configuration setting included in neo4j.conf. The db.temporal.timezone setting this one can be used in order to configure default timezone for our server. And By default timezone is set to UTC (Z).
db.temporal.timezone=Asia/Kolkata
Thanks