format() function formats its argument as a string. It accepts all data types, including dates, Booleans, numbers, and even strings.
format(number) format(Boolean) format(date) format(string)
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 (changes with now()'s value) "There are " + format(10) + " 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.
View and Duplicate Database
“Age” Property Formula
// Compressed "⏳ " + prop("Name") + " is " + format(dateBetween(now(), prop("Birthday"), "years")) + " years old." // Expanded "⏳ " + prop("Name") + " is " + format( dateBetween( now(), prop("Birthday"), "years" ) ) + " years old."
This formula outputs a sentence stating how old each character is based on their birthday.
To obtain the character’s age, we use the dateBetween function to find the number of years between now and the character’s 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.