apoc.temporal.formatDuration
Syntax |
|
||
Description |
Formats the given duration into the given time format. |
||
Arguments |
Name |
Type |
Description |
|
|
The duration value to be formatted into a string. |
|
|
|
The format to return the duration in. |
|
Returns |
|
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 |
---|---|
|
year |
|
days |
|
months of year |
|
quarters of year |
|
weeks |
|
hours |
|
minutes of hour |
|
seconds of minutes |
|
nanoseconds of seconds |
|
milliseconds |
|
nanoseconds |
|
ISO nanoseconds, i.e. with trimmed right zero. e.g. |
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;
output |
---|
"01" |
RETURN apoc.temporal.formatDuration( duration({seconds: 10000}), "hour_minute") AS output;
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
output |
---|
"02 years 01 months 001 weeks 11 days - 01:01:00 8765" |