apoc.temporal.formatDuration

Details

Syntax

apoc.temporal.formatDuration(input, format)

Description

Formats the given duration into the given time format.

Arguments

Name

Type

Description

input

ANY

The duration value to be formatted into a string.

format

STRING

The format to return the duration in.

Returns

STRING

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;
Results
output

"01"

RETURN apoc.temporal.formatDuration( duration({seconds: 10000}), "hour_minute") AS output;
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
Results
output

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