Extracting DATE only from ISO DATE and TIME in templater

What I’m trying to do

Extract the date only from ISO date in templater script to append to new file name.

I created a Templater script to record details about future air travel as properties.
I wanted to create an Obsidian property of type DATE and TIME by default hence the use of date format.
I enter a future ISO date captured via system.prompt . I then want to append the DATE only to title, but when I add data variable to title using tp.file.rename I get an error because the “:” in the Date field, YYYY-MM-DD HH:MM PM, causes an invalid file name.

TemplaterError: File name cannot contain any of these characters: \ / :
at Object.eval [as rename]

<%*
let adate = await tp.system.prompt(“Arrive date YYYY-MM-DD HH:MM PM”)
let ddate = await tp.system.prompt(“Depart date YYYY-MM-DD HH:MM PM”)
titleName = "E- Travel " + ddate
await tp.file.rename(titleName)
tR += “—”
-%>

creationDate: <% tp.date.now() %>
ddate: <%* tR += ddate %>
adate: <%* tR += adate %>
title: <%* tR += titleName %>


Things I have tried

I tried adding
let ddater = ddate.setHours(0,0,0,0)
I tried to use .format(“YYYY-MM-DD”)
I can do separate capture of date and time but wanted to solve this,.

searched
Templater docs
redit

Solved my own problem. If others are stumped as well here it is:

let ddateISO = await tp.system.prompt(“Depart date YYYY-MM-DD HH:MM PM”)
let ddate = ddateISO.split(" ", 1)

I then use ddate variable.

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