apoc.date.fields

Function APOC Core

apoc.date.fields('2012-12-23',('yyyy-MM-dd')) - return columns and a map representation of date parsed with the given format with entries for years,months,weekdays,days,hours,minutes,seconds,zoneid

Signature

apoc.date.fields(date :: STRING?, pattern = yyyy-MM-dd HH:mm:ss :: STRING?) :: (MAP?)

Input parameters

Name Type Default

date

STRING?

null

pattern

STRING?

yyyy-MM-dd HH:mm:ss

Usage Examples

The date parameter is a date string in an ISO8601 standard format

The pattern parameter supports values defined under Patterns for Formatting and Parsing of the Java DateTime formats

The following returns the fields of a date:

RETURN apoc.date.fields("2020-11-04", "YYYY-MM-dd") AS fields;
Table 1. Results
fields

{days: 4, zoneid: "UTC", months: 11}

The following returns the fields of a datetime:

RETURN apoc.date.fields("2020-11-04T10:30:21", "YYYY-MM-dd'T'HH:mm:ss") AS fields;
Table 2. Results
fields

{hours: 10, seconds: 21, months: 11, minutes: 30, days: 4, zoneid: "UTC"}

The following returns the fields of a datetime that contains a timezone:

RETURN apoc.date.fields("2020-11-04T10:30:21+01:00", "YYYY-MM-dd'T'HH:mm:ssz") AS fields;
Table 3. Results
fields

{hours: 10, seconds: 21, months: 11, minutes: 30, days: 4, zoneid: "+01:00"}

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.