apoc.date.format

Details

Syntax

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

Description

Returns a STRING representation of the time value. The time unit (default: ms), date format (default: ISO), and time zone (default: current time zone) can all be changed.

Arguments

Name

Type

Description

time

INTEGER

The timestamp since epoch to format.

unit

STRING

The unit of the given timestamp. The default is: ms.

format

STRING

The format to convert the given temporal value to. The default is: yyyy-MM-dd HH:mm:ss.

timezone

STRING

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

Returns

STRING

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

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

The timezone parameter can be specified with GMT or database (text) name, as listed for timezones

The following converts a datetime in epoch millis to yyyy-MM-dd format:

WITH datetime("2020-11-04T11:23:22").epochMillis AS datetime
RETURN apoc.date.format(datetime, "ms", "yyyy-MM-dd") AS output;
Results
output

"2020-11-04"

The following converts a GMT datetime in epoch millis to yyyy-MM-dd’T’HH:mm:ssz format, using the Australian/Sydney timezone:

WITH datetime("2020-11-04T11:23:22+00:00").epochMillis AS datetime
RETURN apoc.date.format(datetime, "ms", "yyyy-MM-dd'T'HH:mm:ssz", "Australia/Sydney") AS output;
Results
output

"2020-11-04T22:23:22AEDT"