Find and Insert Date in Format "YYYY.MM.DD ddd." from Date in Format "YYYY.MM.DD ddd." (i.e. look up day of the week)

Things I have tried

I’ve done some looking and it seems like some people are using some functions with tp.file.title() and/or tp.date.now() to do some manipulation. I don’t have any real experience with those or understanding of where these would be used or how best to do it. I need to be able to input a date in format YYYY.MM.DD and get out date in format YYYY.MM.DD ddd. and I’m not sure how these would do that.

What I’m trying to do

I want a to use a template to find the day of the week to correspond to a date that is entered. This would mean I know the date in the format YYYY.MM.DD and I want to be able to insert the ddd. portion on the end (or overwrite it or whatever) to be able to get the full date in the format YYYY.MM.DD ddd. inserted, for example this would mean I have a date, 2023.02.01 (in the past from the date I’m writing this) and I want a template/Obisdian/program to go find out what the day of the week is for that date (Wednesday) and then insert 2023.02.01 Wed.. I don’t know if this is a function, or already included inside of another community plugin, or if this is something I can quickly write up in Templater. Any help appreciated. I know I can find the date using websites that will tell you the day of the week corresponding to a given calendar date, but I want it all to be able to be done internally inside Obsidian as I write and not have to jump out, look it up, and then jump back in. Small amount of time for one, but it adds up as I continue to need to do it.

I would suggest using a Templater execution command template for this. And I would have it check if anything is selected, tp.file.selection() (I think), and if nothing selected then ask for the date.

In either case make a date out of it, and format to your liking, and insert result.

This template you should then hook up to a hotkey for ease of access.

I’m on mobile, so can’t write a suggestion just now.

1 Like

Try something like the following:

<%*
let myDate = tp.file.selection()
if ( myDate == "" ) {
  myDate = await tp.system.prompt("Enter a date")
}

tR += tp.date.now("YYYY.MM.DD ddd", 0, myDate, "YYYY.MM.DD")
%>

Insert that into a template file in your designated template folder (See Settings > Templater > Template folder location )

To add a hotkey do this:

  • Scroll down to Settings > Templater > Template Hotkeys, and the buttons belows
  • Hit the “Add new hotkey for template”
  • Go to the box which appeared above the button, and enter the name of your template (with folder in front)
  • Hit the plus icon to the right of the template, this opens up another window where you’ll see the Templater commands
  • Hit the plus icon to the left of line with your template command, and select a hotkey
  • Hover with your mouse over the newly set hotkey, just to verify it doesn’t collide with any other hotkeys. If it does, remove and try again

Now you can in a document of yours try either selecting a date and hit the hotkey, or just hit the hotkey where you want to insert a date.

1 Like

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