Temporal functions - format
format()Cypher 25 onlyIntroduced in Neo4j 2025.09
The format()
function creates dynamically formatted string representations of temporal instance and duration types.
Syntax |
|
||
Description |
Returns the temporal value as an ISO-formatted |
||
Arguments |
Name |
Type |
Description |
|
|
A temporal value to be formatted. |
|
|
|
A pattern used to format the temporal value. If the pattern is not provided the value will be formatted according to ISO 8601. |
|
Returns |
|
The output format can be customized via the |
The |
If no pattern is specified, the function returns an ISO-formatted string. |
Most characters yield a different output when they are repeated. |
Some characters cannot be applied to certain types, for instance, |
Any character that is not reserved, other than |
Instance types
Cypher®'s instance types are DATE
, LOCAL TIME
, ZONED TIME
, LOCAL DATETIME
and ZONED DATETIME
.
For more information, see Values and types → temporal instants.
Use the characters in String pattern characters to create a string pattern for instance types.
Examples
WITH datetime('1986-11-18T6:04:45.123456789+01:00[Europe/Berlin]') AS dt
RETURN format(dt, "MM/dd/yyyy") AS US, format(dt, "dd/MM/yyyy") AS EU
US | EU |
---|---|
|
|
Rows: 1 |
WITH datetime('1986-11-18T6:04:45.123456789+01:00[Europe/Berlin]') AS dt
RETURN format(dt, "EEEE, MMMM d, G uuuu") AS instanceString
instanceString |
---|
|
Rows: 1 |
Four occurrences of E
and M
(text presentations) output the full form of the day and month.
WITH datetime('1986-11-18T6:04:45.123456789+01:00[Europe/Berlin]') AS dt
RETURN format(dt, "DDD'nd day of the year,' c'rd day of the week'") AS instanceString
instanceString |
---|
|
Rows: 1 |
WITH datetime('1986-11-18T6:04:45.123456789+01:00[Europe/Berlin]') AS dt
RETURN format(dt, "k:mm z") AS CET, format(dt, "K:mm O") AS GMT
CET | GMT |
---|---|
|
|
Rows: 1 |
WITH datetime('1986-11-18T6:04:45.123456789+01:00[Europe/Berlin]') AS dt
RETURN format(dt, "LLL d,' minute 'm', second 's', millisecond of the day 'A") AS instanceString
instanceString |
---|
|
Rows: 1 |
Three occurrences of L
(number/text presentation) output the short form ("Nov").
WITH datetime('1986-11-18T6:04:45.123456789+01:00[Europe/Berlin]') AS dt
RETURN format(dt, "pppYY") AS instanceString
instanceString |
---|
|
Rows: 1 |
The three occurrences of p
add one space character of padding to the two digit form output by two occurrences of Y
.
String pattern characters
Character | Meaning | Presentation | Examples |
---|---|---|---|
|
era |
text |
AD; Anno Domini; A |
|
year |
year |
2004; 04 |
|
year-of-era |
year |
2004; 04 |
|
day-of-year |
number |
189 |
|
month-of-year |
number/text |
7; 07; Jul; July; J |
|
day-of-month |
number |
10 |
|
modified-julian-day |
number |
2451334 |
|
quarter-of-year |
number/text |
3; 03; Q3; 3rd quarter |
|
week-based-year |
year |
1996; 96 |
|
week-of-week-based-year |
number |
27 |
|
week-of-month |
number |
4 |
|
day-of-week |
text |
Tue; Tuesday; T |
|
localized day-of-week |
number/text |
2; 02; Tue; Tuesday; T |
|
aligned-week-of-month |
number |
3 |
|
am-pm-of-day |
text |
PM |
|
period-of-day |
text |
in the morning |
|
clock-hour-of-am-pm (1-12) |
number |
12 |
|
hour-of-am-pm (0-11) |
number |
0 |
|
clock-hour-of-day (1-24) |
number |
24 |
|
hour-of-day (0-23) |
number |
0 |
|
minute-of-hour |
number |
30 |
|
second-of-minute |
number |
55 |
|
fraction-of-second |
fraction |
978 |
|
milli-of-day |
number |
1234 |
|
nano-of-second |
number |
987654321 |
|
nano-of-day |
number |
1234000000 |
|
time-zone ID |
zone-id |
America/Los_Angeles; Z; -08:30 |
|
generic time-zone name |
zone-name |
Pacific Time; PT |
|
time-zone name |
zone-name |
Pacific Standard Time; PST |
|
localized zone-offset |
offset-O |
GMT+8; GMT+08:00; UTC-08:00 |
|
zone-offset 'Z' for zero |
offset-X |
Z; -08; -0830; -08:30; -083015; -08:30:15 |
|
zone-offset |
offset-x |
+0000; -08; -0830; -08:30; -083015; -08:30:15 |
|
zone-offset |
offset-Z |
+0000; -0800; -08:00 |
|
pad next |
pad modifier |
1 |
|
escape for text |
delimiter |
|
|
single quote |
literal |
Duration types
Use the characters in String pattern characters to create a string pattern for duration types.
Cypher’s duration type DURATION
has components and component groups.
For more information, see see Values and types → components of durations.
If the string pattern contains a character from a component group but does not contain a character denoting a longer duration from the same group, format()
converts the longer duration to the equivalent duration with the character that is present.
For example a missing y
(year) will be converted to four quarters, if q
is present in the string pattern.
This is because without a reference point, there is no way to determine the specifics of a duration.
Examples
WITH duration({years: 1, months: 4}) AS d
RETURN format(d, "y 'years' q 'quarters' M 'months'") AS withYears, format(d, "q 'quarters' M 'months'") AS withoutYears
withYears | withoutYears |
---|---|
|
|
Rows: 1 |
WITH duration({weeks: 3, days: 4}) AS d
RETURN format(d, "w 'weeks' d 'days'") AS withWeeks, format(d, "d 'days'") AS withoutWeeks
withWeeks | withoutWeeks |
---|---|
|
|
Rows: 1 |
WITH duration({days: 4, hours: 5, minutes: 6, seconds: 7}) AS d
RETURN format(d, "h 'hours' m 'minutes'") AS withHours, format(d, "m 'minutes'") AS withoutHours
withHours | withoutHours |
---|---|
|
|
Rows: 1 |
Note how the four days cannot be converted to hours or minutes and do not affect the query result. Days are in a different component group than hours and minutes, see Allowed characters for a duration type string pattern.