format(number) format(Boolean) format(date) format(string) format(list) number.format() Boolean.format() date.format() string.format() list.format()
format() is very useful for converting data types within Notion formulas.
Good to know: Notion formulas can only output a single data type, and comparison operators can only compare data that share the same type.
See Converting Data Types to learn all of the ways to convert data in Notion formulas.
format(4) /* Output: "4" (as a string) */ format(5+5) /* Output: "10" (as a string) */ format(true) /* Output: "true" (as a string) */ format(5>4) /* Output: "true" (as a string) */ format(now()) /* Output: "June 20, 2022 2:23 PM" (as a string, changes with now()'s value) */ /* Automatic conversion of a number to a string */ "There are " + prop("Number") + " Straw Hat members." /* Output: There are 10 Straw Hat members. */
This example database uses the
format() function to output a string stating the age of each character.
"⏳ " + prop("Name") + " is " + dateBetween( now(), prop("Birthday"), "years" ) + " years old."
This formula outputs a sentence stating how old each character is based on their birthday.
dateBetween() returns a number, so we use the
format() function to convert it to a string.
Note: To keep thinks simple, this example formula doesn’t use conditional logic to determine whether the string should output “year” or “years” (accounting for plurality). To see an example that does, check out the length function.