Daily Notes and calculated Date

Hi,

I like to have a navigational option in my daily notes, so I can jump to

  • tomorrow
  • yesterday
  • this month
    Taken from this article, I managed to establish “this month” by using
    “current month [[{{date:YYYY-MM}}]]”, which jumps to my monthly noted, being generated in “[[2020-11]]” style.

The main question is: how can I calculate the date for tomorrow?
I already tried several variations of
{{date:YYYY-MM-DD+1}}".
Also inserting
moment().format();
does not work at all.

Help anybody :question:

2 Likes

As I understand there is no built-in method of doing this. However, if you are open to installing a text expander of some sort, then you would be able to do this (by typing a “trigger” into your daily note after you create it).

This thread starts with an example of achieving it with the Espanso text expander, but there are examples for others in the comments too:

1 Like

Plus 1 on the TextExpander

I have a snippet I run that inserts the yesterday and tomorrow dates into my daily notes.

1 Like

OK, so I need to check the concept of a text expander.
…and nee to check, if it will be possible to install all things necessary on my different machines.

I was hoping, that some sort “moment().format(++decent calulation string++);” will do the job…

Will espanso (or the like) be available as a plugin?

There is a thread in the plugin ideas category proposing this, but no official plans of such a plugin. Once the plugin API progresses a little further (its currently in alpha stage) there will likely be an abundance of plugins to choose, which may indeed include such a plugin if someone develops one

1 Like

You could also have a look at the “Natural Language Dates” plugin, which expands, e.g., “tomorrow” to a date, with configurable date format.

I created a template for Daily notes with “yesterday” and “tomorrow”, and I expand it with CTRL-Y (default shortcut for the plugin) on each new day.

1 Like

Maybe this is useful for you?

// Created by Oliver Epper
// https://oliver-epper.de

import { Plugin, PluginSettingTab, Setting } from 'obsidian';

export default class MyPlugin extends Plugin {
	settings: Settings;

	async onload() {

		this.settings = (await this.loadData()) || new Settings();

		this.addCommand({
			id: 'insert-daily-breadcrumbs',
			name: 'Insert Daily Breadcrumbs',
			callback: () => {
				this.getDateCommand();
			},
		});

		this.addSettingTab(new SettingsTab(this.app, this));
	}


	getMoment(date: Date): any {
		return (window as any).moment(date);
	}

	getDateCommand() {
		let activeLeaf: any = this.app.workspace.activeLeaf;
		let editor = activeLeaf.view.sourceMode.cmEditor;
		editor.replaceSelection(
		  '◀️ [[' + this.getMoment(new Date()).subtract(1, 'day').format(this.settings.format) + ']] || ' +
		  '[[' + this.getMoment(new Date()).add(1, 'day').format(this.settings.format) + ']] ▶️'
		);
	  }
}

class Settings {
	format: string = "YYYY-MM-DD";
}

class SettingsTab extends PluginSettingTab {
	display(): void {
		let { containerEl } = this;
		const plugin: any = (this as any).plugin;

		containerEl.empty();

		new Setting(containerEl)
			.setName("Datumsformat")
			.setDesc("Format für das Datum der Breadcrumbs")
			.addMomentFormat((text) =>
				text
					.setDefaultFormat("YYYY-MM-DD")
					.setValue(plugin.settings.format)
					.onChange((value) => {
						if (value === "") {
							plugin.settings.format = "YYYY-MM-DD";
						} else {
							plugin.settings.format = value.trim();
						}
						plugin.saveData(plugin.settings);
					})
			);
	}
}

Hi @oliep, what does this do (not sure which comment above your code is referring to/solving), and more importantly, how do i install it/deploy it/use it?

1 Like