10.1. Temporal Functions

This section describes functions that can be used to format temporal values.

These functions can be used to format temporal values using a valid DateTimeFormatter pattern.

10.1.1. Formatting Temporal Types

You can pass through any temporal type (Date, Time, DateTime, LocalTime, LocalDateTime, Duration) along with a pattern. Please note that if the pattern is invalid for the value that you pass in (for example HH for hours on a Date value or DD for day on a Time value), an Exception will be thrown.

Format as date. 

RETURN apoc.temporal.format( date(), 'YYYY-MM-dd') AS output;

Table 10.1. Results
Output

"2019-06-24"

Format as date and time. 

RETURN apoc.temporal.format( datetime(), 'YYYY-MM-dd HH:mm:ss.SSSSZ') AS output;

Table 10.2. Results
Output

"2019-06-24 13:56:56.8550+0000"

Format as time. 

RETURN apoc.temporal.format( localtime(), 'HH:mm:ss.SSSS') AS output;

Table 10.3. Results
Output

"13:57:31.9250"

View full pattern listing

You can also pass a ISO DATE TIME pattern, the list is available here ISO_DATE

For example:

Format as date. 

RETURN apoc.temporal.format( date( { year: 2018, month: 12, day: 10 } ), 'date' ) as output;

Table 10.4. Results
Output

"2018-12-10"

Format as date and time. 

RETURN apoc.temporal.format( localdatetime( { year: 2018, month: 12, day: 10, hour: 12, minute: 34, second: 56, nanosecond: 123456789 } ), 'ISO_LOCAL_DATE_TIME' ) as output;

Table 10.5. Results
Output

"2018-12-10T12:34:56.123456789"

Format as date. 

RETURN apoc.temporal.format( date( { year: 2018, month: 12, day: 10 } ), 'ISO_DATE' ) as output;

Table 10.6. Results
Output

"2018-12-10"

10.1.2. Formatting Durations

When attempting to format a duration, the procedure will attempt to create a date (01/01/0000) and add the duration. This allows you to provide a consistent format as above.

Format as duration. 

RETURN apoc.temporal.format( duration.between( datetime.transaction(), datetime.realtime() ) , 'HH:mm:ss.SSSS') AS output;

Table 10.7. Results
Output

"00:00:00.0110"