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

Accessing temporal fields using Cypher

Fields of a temporal type can be retrieved using Cypher’s instance.field component access.

Cypher syntax for accessing a temporal field
RETURN datetime().year

Fields can also be accessed dynamically:

Cypher syntax for accessing a temporal field dynamically
RETURN datetime()[$fieldNameAsParam]

Usage Examples

The unit parameter supports the following values:

  • ms, milli, millis, milliseconds (Equivalent to instant.millisecond in Cypher)

  • s, second, seconds (Equivalent to instant.second in Cypher)

  • m, minute, minutes (Equivalent to instant.minute in Cypher)

  • h, hour, hours (Equivalent to instant.hour in Cypher)

  • d, day, days (Equivalent to instant.day in Cypher)

  • w, weekday, weekdays (Equivalent to instant.dayOfWeek in Cypher)

  • month, months (Equivalent to instant.month in Cypher)

  • year, years (Equivalent to instant.year in Cypher)

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

The following examples return the hours of a datetime using both APOC and Cypher:

apoc.date.field
WITH datetime("2020-11-04T10:30:00").epochMillis AS datetime
RETURN apoc.date.field(datetime, "hours") AS hour;
Using Cypher’s temporal instance access
WITH datetime("2020-11-04T10:30:00") AS datetime
RETURN datetime.hour AS hour;
Results
hour

10

The following examples return the weekday of a datetime using both APOC and Cypher:

apoc.date.field
WITH datetime("2020-11-04T10:30:00").epochMillis AS datetime
RETURN apoc.date.field(datetime, "weekday") AS weekday;
Using Cypher’s temporal instance access
WITH datetime("2020-11-04T10:30:00") AS datetime
RETURN datetime.dayOfWeek AS weekday;
Results
weekday

3