obsidian-tracker icon indicating copy to clipboard operation
obsidian-tracker copied to clipboard

Is it possible to get a date from a file's name?

Open ghost opened this issue 5 months ago • 2 comments

I have a periodic notes system, and I use trackers in those periodic notes. (It's so awesome btw — huge thanks to this plugin's creator!)

However, sometimes I make those periodic notes after the fact, so the cDate is, say, Thursday, but it's actually a daily note for Tuesday. That means that relative dates in the trackers don't work right. it also means that a tracker showing the past week works well in the moment, but then if I look back at it a month later, it shows the most recent week, rather than the week leading up to the day that note was meant for.

The way I handle this is by making the note title reflect the day or period (week, month, quarter, year) it's for. Can I get a start/end date from the note title within the Tracker plugin? For example, if I have a daily note called 2024-01-14, can I set the startDate based on that, or use a date relative to that note title date?

ghost avatar Jan 14 '24 06:01 ghost

I might be having trouble understanding your request here. Yes it is possible to get the date from the file name (it's one of the default search locations). Could you please use the issue template to fully report what you are wanting to achieve?

lazyguru avatar Jan 14 '24 07:01 lazyguru

@lazyguru It's more likely me who's not understanding! Happy to use the issue template:


Expected Behavior

Suppose there's a note with title 2024-01-04 and with a tracker is supposed to show data for the week leading into 2024-01-04, that is 2023-12-29 through 2024-01-04. I would expect something like startDate: date(file.name) to accomplish this.

Current Behavior

Using startDate: date(file.name) or startDate: date(file.name, 'YYYY-MM-DD') gives an error:

Invalid startDate, the format of startDate may not match your dateFormat

Using a relative date as startDate: -1w works, but it seems to show a week's worth of data relative to the current date, which is no longer 2024-01-04. (Or maybe it's relative to the file's cDate? I'm not entirely sure.)

Possible Solution

If there was a way to get a date from the note title, as in date(file.name), that would be a great solution. (The Dataview plugin, for example, supports this sort of syntax: date(this.file.name) with an optional second input that's a format string.) Maybe there's a way to do this already and I'm not aware of it, but I looked hard through the docs. I thought at first that searchType: fileMeta would allow for this, but the note's title is not in the metadata that can be accessed that way. (Also, the data I'm tracking is contained in the frontmatter.)

Steps to Reproduce (for bugs)

  1. Start with the example vault and take this tracker from the TestFrontmatter file:
searchType: frontmatter
searchTarget: sleep-times[0], sleep-times[1]
folder: Periodic/Daily
datasetName: Sleep, Wake
startDate: -1w
line:
	xAxisLabel: Day
	xAxisTickLabelFormat: dd
	yAxisLabel: Time
	lineColor: steelblue, orange
	pointColor: '#858585'
	showLegend: true
	fillGap: true
  1. Copy this tracker to diary/2021-01-10.
  2. Try the above methods to make the tracker show data for a week leading up to 2021-01-10 by getting that date from the note name.

Context

I have a periodic notes system, and I use trackers in those periodic notes. However, sometimes I make those periodic notes after the fact, so the cDate is, say, Thursday, but it's actually a daily note for Tuesday. That means that relative dates in the trackers don't work right.

It also means that a tracker showing the past week works well in the moment, but then if I look back at it a month later, it shows the most recent week, rather than the week leading up to the day that note was meant for.

The way I handle this is by making the note title reflect the day or period (week, month, quarter, year) it's for. Can I get a start/end date from the note title within the Tracker plugin? For example, if I have a daily note called 2024-01-14, can I set the startDate based on that, or use a date relative to that note title date?

ghost avatar Jan 14 '24 22:01 ghost