These functions can be used to format temporal values using a valid DateTimeFormatter
pattern.
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.
apoc.temporal.format( date(), 'YYYY-MM-dd')
apoc.temporal.format( datetime(), 'YYYY-MM-dd HH:mm:ss.SSSSZ')
apoc.temporal.format( localtime(), 'HH:mm:ss.SSSS')
apoc.temporal.format( localtime(), 'HH:mm:ss.SSSS')
You can also pass a ISO DATE TIME pattern, the list is available here ISO_DATE
For example:
apoc.temporal.format( date( { year: 2018, month: 12, day: 10 } ), 'date' ) as output
apoc.temporal.format( localdatetime( { year: 2018, month: 12, day: 10, hour: 12, minute: 34, second: 56, nanosecond: 123456789 } ), 'ISO_LOCAL_DATE_TIME' ) as output
apoc.temporal.format( date( { year: 2018, month: 12, day: 10 } ), 'ISO_DATE' ) as output
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.
apoc.temporal.format( duration.between( datetime.transaction(), datetime.realtime() ) , 'HH:mm:ss.SSSS')