apoc.date.fields

Details

Syntax

apoc.date.fields(date [, pattern ])

Description

Splits the given date into fields returning a MAP containing the values of each field.

Arguments

Name

Type

Description

date

STRING

A string representation of a temporal value.

pattern

STRING

The format the given temporal is formatted as. The default is: yyyy-MM-dd HH:mm:ss.

Returns

MAP

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;
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;
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;
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.