apoc.temporal.formatDuration

This function is deprecated. Use Cypher’s format() function instead.

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.

apoc.temporal.formatDuration
RETURN apoc.temporal.formatDuration(duration({seconds: 6000}), "hour") AS output;
Cypher’s format function
RETURN format(duration({seconds: 6000}), "hh") AS output;
Results
output

"01"

apoc.temporal.formatDuration
RETURN apoc.temporal.formatDuration( duration({seconds: 10000}), "hour_minute") AS output;
Cypher’s format function
RETURN format( duration({seconds: 10000}), "hh:mm") AS output;
Results
output

"02:46"

apoc.temporal.formatDuration
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' dd 'days' - HH:mm:ss SSSS") AS output
Cypher’s format function
WITH duration.between(datetime('2017-06-02T18:40:32.1234560'), datetime('2019-07-13T19:41:33')) AS duration
RETURN format(duration, "yy 'years' MM 'months' dd 'days' - HH:mm:ss SSSS") AS output
Results
output

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