Add automatic alias with different date format for meeting notes

Hey there,

I am trying to add an automatic alias to my meeting notes. I only want to change the date format. For sorting reasons I use YYYY-MM-DD as the date format but want to use DD.MM.YYYY format when refering to my meeting notes. This is obviosly because I am used to this format and so are my collegues. My current template looks like this:

---
date: <% tp.date.now("YYYY-MM-DD") %>
<%*
let title = tp.file.title
if (title.startsWith("Untitled")){
	title = await tp.system.prompt("Title");
	await tp.file.rename(title)
	await tp.file.move("Meetings/" + title + " " + tp.date.now("YYYY-MM-DD"))
}
%>
---
# Teilnehmende

# Agenda

But I would like to include something like this, where print.alias.here ist obviously a placeholder.

	alias = await title + " " + tp.date.now("DD.MM.YYYY")
	print.alias.here

If you define date using “YYYY-MM-DD” in the frontmatter, that date is readily available within dataview queries as file.day. As such, there is no need to define the aliases or not to use your preferred date format within the title.

So the following should suffice:

---
date: <% tp.date.now("YYYY-MM-DD") %>
<%*
let title = tp.file.title
if (title.startsWith("Untitled")){
	title = await tp.system.prompt("Title");
	await tp.file.rename(title)
	await tp.file.move("Meetings/" + title + " " + tp.date.now("DD.MM.YYYY"))
}
%>
---
# Teilnehmende

# Agenda

For the sake of argument, here is an alternative method just responding to your question:

---
date: <% tp.date.now("YYYY-MM-DD") %>
<%*
let title = tp.file.title
let titleAlias
if (title.startsWith("Untitled")){
    title = await tp.system.prompt("Title");
    await tp.file.rename(title)
    titleAlias = title + " " + tp.date.now("DD.MM.YYYY")
    await tp.file.move("Meetings/" + titleAlias)
    tR += "alias: " + titleAlias
}
%>
---
# Teilnehmende

# Agenda

Just for the fun of it: <% titleAlias %>

The last line is not needed, but since we’ve now declared the variable titleAlias it’s available throughout the template using that syntax. :smiley:

No need to await the setting of the title alias either since no file or user operations (aka no async operations) are done setting the value.

1 Like

Thanks a lot. I am glad that you added the alternative.
My sorting-issue did not corrospond to dataview but to the side panel. There the DD.MM.YYYY format messes with the sorting while the YYYY-MM-DD format sorts correctly. It was recommended to keep this format for that reason. Now I can keep my meeting notes sorted while being able to refer to the other format without the hustle to add the alias manually.

1 Like

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