Querying dates in notes

Things I have tried

I searched Google and this forum for things like “dataview date list”.

What I’m trying to do

I have a bunch of notes that I’m gradually importing into Obsidian that are keyed by date. It’s not just the creation date of the note; there are often several entries in each note, each with its own date. These are not sequential; there are entries for various overlapping dates in various notes.

I would like to be able, once I get these imported, to see these entries organized by date. I presume that Dataview is the way to do this, in the same way that you can build a list of quotes.

My question is, how should I format these dates in such a way that future queries will be easy? I am very new to Dataview (and fairly new to Obsidian). Should I use tags? Link the dates somehow? Or just use one consistent date format and trust that the query will find them?

The format I’ve been using as I import them is something like

##### Page 67 — 5/30/2012
Text of entry

But of course there may not always be a page number.

The existing files aren’t in a consistent format (to include the date format), so now’s my chance to format them in a future-proof way.

DataView supports dates as a data format (see Data Annotation - Dataview). They have to be in ISO format, like ##### Page 67 — [date:: 2012-05-30]. The brackets in that example allow you to put the data anywhere on the line.

DataView can’t query individual blocks — only pages and tasks — so it might not work for your case…yet. Support for sections and blocks is coming.

Outside of Obsidian, you could use a script to search your notes and build a list of embeds to paste back into a note. In shell, for example (maybe not the best choice but my knowledge is limited), you could grab all the headings with grep (including the filenames in the output), rearrange each with sed to put the date first, sort them, then use sed to transform them into embeds.

1 Like

That helps, thanks.

Followup question: What if I want to do a similar thing with page numbers, so I could sort entries in a given file, which are currently ordered by date, by page number? Should I just do ##### [Page:: 67] — [date:: 2012-05-30]? Or is reordering entries more than I should expect from Dataview?

Yup, that format should do what you want. I believe listing things in different orders is doable.

(I forgot to mention in my first reply that I only tested DataView a little for myself and never got around to trying any queries, so anything I say about it is just what I picked up when starting to learn it.)

1 Like

Cool. Thanks. Last question: Is there a way to make the resulting format less…ugly?

looks a lot nicer than

, and I don’t need the word “date” in there.

A CSS snippet should do it but I don’t know the specifics of the styling or markup. Looks like there’s some background-color and border-radius to cancel out, and display: none to put on the date label (but not in editing mode, and specifically targeting the content so you don’t hide every data label).

1 Like

Thanks; knowing it’s possible with CSS should be enough for me to figure it out.

Now I’m just afraid I’m going to try to make everything into metadata!

About the “ugly” render of the fields:

  1. if you want normal render (without any style effect) you can disable in Settings / Dataview the inline fields highlighting;
  2. about hide date in [date:: 2012-05-30], if inline fields highlighting is enabled, you can use the format (date:: 2012-05-30), i.e., changing the brackets. With this round brackets the render hides the field key (in your case “date”).
  3. you can explore other themes with specific styles for these inline fields: for example, Minimal theme.
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.