Last active
July 5, 2024 14:48
-
-
Save jordanlambrecht/0a9f492b02fbc3b9bf9fafd15a0a16e5 to your computer and use it in GitHub Desktop.
Notion Formula: Time Difference in Years, Months, and Days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This formula calculates the difference between the current date and a specified “Date Billed” property in Notion. It breaks down the time difference into years, months, and days, and formats the output in a human-readable string. The formula also correctly pluralizes the time units and omits any unit that has a value of zero. | |
# Logic: | |
# - if the date range is less than a month, hide the month and years text so it doesn't show 0 | |
# - if the time period = 1, make it singular instead of plural | |
# - my example uses a date column called 'Date Billed' and outputs to a column named 'Past Due' | |
# - Not 100% accurate, as it assumes there are 30 days in a month | |
( | |
if(floor(dateBetween(now(), prop("Date Billed"), "days") / 365) > 0, | |
format(floor(dateBetween(now(), prop("Date Billed"), "days") / 365)) + | |
(if(floor(dateBetween(now(), prop("Date Billed"), "days") / 365) == 1, " year ", " years ")), | |
"" | |
) | |
) + | |
( | |
if(floor(mod(dateBetween(now(), prop("Date Billed"), "days"), 365) / 30) > 0, | |
format(floor(mod(dateBetween(now(), prop("Date Billed"), "days"), 365) / 30)) + | |
(if(floor(mod(dateBetween(now(), prop("Date Billed"), "days"), 365) / 30) == 1, " month ", " months ")), | |
"" | |
) | |
) + | |
( | |
if(mod(dateBetween(now(), prop("Date Billed"), "days"), 30) > 0, | |
format(mod(dateBetween(now(), prop("Date Billed"), "days"), 30)) + | |
(if(mod(dateBetween(now(), prop("Date Billed"), "days"), 30) == 1, " day", " days")), | |
"" | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment