apoc.date.format

Function APOC Core

apoc.date.format(12345,('ms|s|m|h|d'),('yyyy-MM-dd HH:mm:ss zzz'),('TZ')) - get string representation of time value optionally using the specified unit (default ms) using specified format (default ISO) and specified time zone (default current TZ)

Signature

apoc.date.format(time :: INTEGER?, unit = ms :: STRING?, format = yyyy-MM-dd HH:mm:ss :: STRING?, timezone =  :: STRING?) :: (STRING?)

Input parameters

Name Type Default

time

INTEGER?

null

unit

STRING?

ms

format

STRING?

yyyy-MM-dd HH:mm:ss

timezone

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

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