Formulas are defined in the formulas section and compute values from note properties, file properties, or other formulas. Use the formula. prefix to reference them in properties or views.
Common Formula Patterns
- Arithmetic:
total: "price * quantity" - Conditional:
status_icon: 'if(done, "✅", "⏳")' - String Formatting:
formatted_price: 'if(price, price.toFixed(2) + " dollars")' - Date Formatting:
created: 'file.ctime.format("YYYY-MM-DD")' - Duration Calculation:
days_old: '(now() - file.ctime).days'
Key Functions
| Function | Signature | Description |
|---|
date() | date(string): date | Parse string to date (YYYY-MM-DD HH:mm:ss) |
now() | now(): date | Current date and time |
today() | today(): date | Current date (time = 00:00:00) |
if() | if(condition, trueResult, falseResult?) | Conditional |
duration() | duration(string): duration | Parse duration string |
file() | file(path): file | Get file object |
link() | link(path, display?): Link | Create a link |
Working with Durations
Subtracting two dates returns a Duration type. To perform math on a duration, you must access a numeric field (like .days) first. Duration does not support .round(), .floor(), or .ceil() directly.
Correct: "(date(due_date) - today()).days.round(0)"
Incorrect: "((date(due) - today()) / 86400000).round(0)"
formulas:
days_until_due: 'if(due, (date(due) - today()).days, "")'
is_overdue: 'if(due, date(due) < today() && status != "done", false)'