apoc.date.field

Details

Syntax

apoc.date.field(time [, unit, timezone ])

Description

Returns the value of one field from the given date time.

Arguments

Name

Type

Description

time

INTEGER

The timestamp in ms since epoch to return a field from.

unit

STRING

The unit of the field to return the value of. The default is: d.

timezone

STRING

The timezone the given timestamp is in. The default is: UTC.

Returns

INTEGER

Usage Examples

The unit parameter supports the following values:

  • ms, milli, millis, milliseconds

  • s, second, seconds

  • m, minute, minutes

  • h, hour, hours

  • d, day, days

  • w, weekday, weekdays

  • month, months

  • year, years

The computed value will be in the unit specified by the unit parameter.

The following returns the hours of a datetime:

WITH datetime("2020-11-04T10:30:00").epochMillis AS datetime
RETURN apoc.date.field(datetime, "hours") AS hour;
Results
hour

10

The following returns the weekday of a datetime:

WITH datetime("2020-11-04T10:30:00").epochMillis AS datetime
RETURN apoc.date.field(datetime, "weekday") AS weekday;
Results
weekday

3

Neo4j 3.4 introduced temporal data types, which are the recommended way of representing dates in Neo4j. Fields of a temporal type can be retrieved using Cypher’s instance.field function. (e.g. datetime({epochMillis: dateInteger}).year) See the Cypher documentation for more details on the syntax.

If, however, you still need to convert timestamp formats, this procedure provides that functionality.