- Sharpen countdown vs diff: countdown is now always relative to now and
no longer accepts a 'from' field (previously identical math to diff
with a custom from, just different message framing).
- Add symmetric frontmatter fallback to countdown (to/deadline), diff
(from/start, to/end), and since (since/created) \u2014 previously only
birthday read frontmatter.
- Add relative date support to parseMoment: today, now, tomorrow,
yesterday, and +/-N offsets (d/w/mo/y/h/m), always relative to now.
Fixes diff's main weakness of needing hardcoded, staling dates.
- Make label verbatim everywhere (was auto-appending ': ' for countdown
only, inconsistent with birthday's verbatim convention).
- Fix silent inline failures: unresolvable type now shows an explicit
error ('Missing or unrecognized type') instead of rendering nothing,
matching fenced-block behavior. Also fixes 'from=X' alone (documented
since-alias) not inferring a type.
- Remove the 'YAML-like' comma-separated inline format from docs \u2014 it
isn't valid non-flow YAML and silently produced nothing; only
key=value and {flow-mapping} are documented now.
- README rewritten to match: field references, frontmatter docs per
type, and a new relative-dates section.
Verified against the real bundled logic (12 behavioral checks) and live
in Obsidian via CDP across both Live Preview and Reading View.
6.3 KiB
Date Calculator
An Obsidian plugin that adds dynamic date calculations to your notes using date-calc fenced code blocks and inline code.
Features
Fenced Code Blocks
Add date-calc code blocks to your notes for rich date calculations:
type: birthday
birthday: 1992-08-16
Inline Code
Use inline code for quick calculations: date-calc: birthday=1992-08-16
Rendering modes: Inline code and fenced blocks both render in Reading view and Live Preview mode. In Source mode, you'll see the literal date-calc: code until you switch to Reading view or Live Preview.
Supported Calculation Types
Birthday (birthday)
Calculates age and time until next birthday.
Fields:
birthday(orbirthdate,date): Birth datelabel(optional): Full prefix text, used verbatim — include your own punctuation (defaults toAge:)
Frontmatter Support: If not provided in the code block, reads birthday/birthdate from the note's frontmatter. If no label is set, a frontmatter name property personalizes the default label automatically (e.g. name: John → John's age:).
Examples:
type: birthday
birthday: 1992-08-16
type: birthday
birthday: 2000-05-21
label: "John's age:"
Countdown (countdown or until)
Time remaining until a target date, always measured from now. For a comparison between two fixed dates, use diff instead.
Fields:
to(ordate,until): Target date/timelabel(optional): Full prefix text, used verbatim (e.g.label: "New Year:")
Frontmatter Support: If to isn't provided in the code block, reads to/deadline from the note's frontmatter.
Example:
type: countdown
label: "New Year:"
to: 2025-12-31 23:59
Since (since)
Time elapsed since an event (or time until, if the event is in the future) — always measured against now.
Fields:
since(orfrom,date): Event date/time
Frontmatter Support: If not provided in the code block, reads since/created from the note's frontmatter.
Example:
type: since
since: 2024-12-20
Difference (diff)
The time difference between two fixed dates — neither has to be "now". For a countdown relative to the present moment, use countdown instead.
Fields:
from(orstart): Start date/timeto(orend): End date/time
Frontmatter Support: If not provided in the code block, reads from/start and to/end from the note's frontmatter.
Examples:
type: diff
from: 2024-02-29
to: 2025-03-01
type: diff
from: 2025-09-19 08:00
to: 2025-09-19 16:30
Inline Usage
You can use inline code for quick calculations:
date-calc: birthday=1992-08-16→ Birthday summarydate-calc: to=2025-12-31 label="New Year:"→ Countdowndate-calc: since=2024-12-20→ Time since eventdate-calc: from=2025-09-19 to=2025-09-20→ Date difference
Formats: Inline code accepts key=value pairs (birthday=1992-08-16) or a flow-mapping YAML object ({type: birthday, birthday: 1992-08-16}).
Frontmatter Integration: Applies to every type, not just birthday — see each type's "Frontmatter Support" above.
Date Formats
| Format | Example | Notes |
|---|---|---|
| Date only | 2026-12-31 |
— |
| Date + time | 2026-12-31 23:59 |
— |
| ISO 8601 | 2026-12-31T23:59:00 |
— |
| Relative keyword | today, now, tomorrow, yesterday |
Resolved at render time |
| Relative offset | +7d, -3mo, +2w, -1y |
Units: d, w, mo, y, h, m (minutes) — always relative to now |
All dates use your local timezone. Birthday calculations normalize to midnight to avoid timezone edge cases; today/relative keywords resolve to your local time at render.
Relative dates are most useful with diff, since countdown/since are already anchored to now by default — e.g. type: diff with from: today and to: +30d gives a fixed 30-day window that doesn't need updating.
Configuration Options
Verbose Output
Control output verbosity globally via settings or per-calculation:
Global: Settings → Date Calc → Verbose output
Per-calculation override:
type: countdown
to: 2026-12-31
verbose: true
Inline: date-calc: countdown to=2026-12-31 verbose=true
verbose: true→ "Countdown: 1 year, 2 months, 15 days"verbose: false→ "1y 2mo 15d"
Hide While Editing
Settings → "Hide result while cursor inside" prevents rendered output from showing while you're editing the code, keeping the raw syntax visible.
Field Reference
Birthday
birthday/birthdate/date— Birth date (falls back to frontmatterbirthday/birthdate)label— Full prefix, verbatim (defaults toAge:, or<frontmatter name>'s age:if set)verbose— Override output format
Countdown
to/until/date— Target date/time (falls back to frontmatterto/deadline)label— Full prefix, verbatimverbose— Override output format
Since
since/from/date— Event date/time (falls back to frontmattersince/created)verbose— Override output format
Diff
from/start— Start date/time (falls back to frontmatterfrom/start)to/end— End date/time (falls back to frontmatterto/end)verbose— Override output format
Type Aliases
For convenience, use these shortcuts:
birthday=bdaycountdown=untildiff=difference
Custom Styling
Target these CSS classes in your snippets:
/* Fenced block results */
.date-calc-block {
color: var(--text-accent);
font-weight: 500;
}
/* Inline code results */
.date-calc-inline {
background: var(--background-secondary);
padding: 2px 6px;
border-radius: 3px;
}
Commands
- Toggle debug — Log decoration activity to console
- Toggle verbose — Switch global verbose mode