apoc.date.field

Function APOC Core

apoc.date.field(12345,('ms|s|m|h|d|month|year'),('TZ')

Signature

apoc.date.field(time :: INTEGER?, unit = d :: STRING?, timezone = UTC :: STRING?) :: (INTEGER?)

Input parameters

Name Type Default

time

INTEGER?

null

unit

STRING?

d

timezone

STRING?

UTC

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;
Table 1. 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;
Table 2. Results
weekday

3

In version 3.4 Neo4j 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.