apoc.temporal.formatDuration

Function APOC Core

apoc.temporal.formatDuration(input, format) | Format a Duration

Signature

apoc.temporal.formatDuration(input :: ANY?, format :: STRING?) :: (STRING?)

Input parameters

Name Type Default

input

ANY?

null

format

STRING?

null

Usage Examples

This function handles a pattern string similar to the one used in DateTimeFormatter.ofPattern(<pattern>), but with some differences. Below is the conversion table between letters and Duration Fields:

letter field

y or Y or u

year

d or D

days

M or L

months of year

q or Q

quarters of year

w or W

weeks

h or H or k`or `K

hours

m

minutes of hour

s

seconds of minutes

n or S

nanoseconds of seconds

A

milliseconds

N

nanoseconds

I

ISO nanoseconds, i.e. with trimmed right zero. e.g. "12300" becomes "123"

It is also possible to use one of a Predefined Java formats or as elastic formats, except ones which require timezone or weekyear, such as basic_date_time or week_date_time.

RETURN apoc.temporal.formatDuration(duration({seconds: 6000}), "hour") AS output;
Table 1. Results
output

"01"

RETURN apoc.temporal.formatDuration( duration({seconds: 10000}), "hour_minute") AS output;
Table 2. Results
output

"02:46"

WITH duration.between(datetime('2017-06-02T18:40:32.1234560'), datetime('2019-07-13T19:41:33')) AS duration
RETURN apoc.temporal.formatDuration(duration, "yy 'years' MM 'months' www 'weeks' dd 'days' - HH:mm:ss SSSS") AS output
Table 3. Results
output

"02 years 01 months 001 weeks 11 days - 01:01:00 8765"