Managing time and date in notes

Managing time in notes - Drawing - 2024-10-27T115033.excalidraw.png|float-left|400

Processing information by time and date intervals is a very common operation in knowledge management and data analysis.

Conceptually, there are two main approaches:

  1. Store complete information in a single field and dynamically derive secondary values whenever you need them.
  2. Store derived data up front so it is immediately available for processing.

Variants of the second approach are common, since the first is only practical when you rely on a single field or property. Both approaches have advantages and trade-offs.

Complete information with dynamically derived data

If you choose this approach, the recommended format is:

YYYY-MM-DD[T]HH:mm:ss[Z]ZZ

This format encapsulates full date-time information, including timezone, and allows you to derive any other value from it.

Derived Information and Simpler Processing

To balance flexibility and usability, include at least:

These fields allow grouping and filtering by multiple time dimensions, supporting both operational and statistical use cases.

Implementation with moment.js and Templater

You can automate field generation in Obsidian templates with code like this:

<%*
   let tt = moment();
-%>
(...)
date: "<% tt.format('YYYY-MM-DD') %>"
month: <% tt.format('MM') %>
monthyear: "<% tt.format('YYYY-MM') %>"
quarter: "<% tt.format('[Q]Q') %>"
quarteryear: "<% tt.format('YYYY-[Q]Q') %>"
week: <% tt.format('ww') %>
weekday: "<% tt.format('dddd') %>"
weekyear: "<% tt.format('gggg-[W]ww') %>"
year: <% tt.format('YYYY') %>
created: <% tt.format('YYYY-MM-DD[T]HH:mm:ss[Z]ZZ') %>

Example Output

date: 2024-05-23
month: 5
monthyear: 2024-05
quarter: Q2
quarteryear: 2024-Q2
week: 21
weekday: Thursday
weekyear: 2024-W21
year: 2024
created: 2024-05-23T18:47:08Z-0600

Best Practice: Consistency

Consistency is key. Place the above snippet in a dedicated template (e.g., Template - Frontmatter - Dates) and include it in other templates with:

<% tp.file.include("[[Template - Frontmatter - Dates]]") %>

This ensures all your notes follow the same structure, making them easier to query, analyze, and maintain over time.