Strip time from date and create a link

I have some zettels that include a YAML key of created with a value in YYYY-MM-DDTHHmm format. For example: created: 2022-03-01T07:13

I want to create a link to the created date’s daily note, which is in YYYY-MM-DD format.

In a Dataview query, I use:

link(created, dateformat(file.created, "YYYY-MM-DD")) AS "date"
	source =

I am trying to get created to link to 2022-03-01, but the time isn’t being removed. I see created as 2022-03-01 07:13.

I have tried using striptime instead of dateformat but the query fails completely when I use that.

Any tips gratefully received.


Solved this by using cday instead.

Thanks to anyone who read this request and even considered it for a second.

You originally wrote:

link(created, dateformat(file.created, "YYYY-MM-DD")) AS "date"

If we expand what you’ve written here, it’ll result in this attempt to create a link:

link( "2022-03-01T07:13", dateformat(null, "YYYY-MM-DD")) as "date"

The first parameter to link() should be the actual path to the file you want to link to, which I reckon would be [[2022-03-01]]. The second parameter, is the display variant of this link. In your case you referred to file.created which is empty, since it should be created, and not file.created. Secondly, dateformat uses a different set of tokens for formatting dates, see link in documentation for datetime(). It refers to Luxon tokens.

Compensating for both of these slight, but vital errors, you should be able to use:

link(dateformat(created, "yyyy-MM-dd")) as date

And then you would respect the value of created field, instead of the file’s creation date (file.cday), which could change depending on synchronisation and other file system anomalies.

1 Like

Many thanks for the explanation; apologies for the naïve errors. :scream:

If created is already an ISO yyyy-MM-dd date, why doesn’t
link(created) as Date work?

In the example below, key can be made into a link: link(key).


created: 2023-05-30
key: lock

	link(dateformat(created, "yyyy-MM-dd")) as Date,

	link(created) as Date

No problem, you tried and was very close, so correcting a few errors is not an issue.
And I’m built that way, that your attempts count for a lot. (If someone on the other hand clearly is fishing for others to do the work for them (or says they’ve tried and even asked ChatGPT), I’m less inclined to help…)

It doesn’t work since the type is date, and it don’t know how to handle it. I reckon, link(string(created)) would work, since that enforces the date to be presented as a string again.

1 Like

I’m just embarrassed and disheartened to make so many basic errors. Hardly a day goes by without reading part of the Dataview, Luxon, and MomentJS documentation and yet I still don’t see things clearly. :sob:

I thought Dataview understood ISO dates and could handle them without any change, but clearly I have assumed too much. Doh. Will have to read the Dataview website again (wish it was more comprehensive and had more examples).

Yes, link(string(created)) works perfectly.

Loads of changes to make to my vault now. :grin:

A thousand thanks.

Please don’t be disheartened, we’re all learning at some level in some area. What’s important is to keep seeking new knowledge and wisdom, and what better way than keep trying and pushing ones boundaries?

The other day I stood in awe of how @FireIsGood conjured up some CSS way behind my knowledge level, and today I helped @Jordan33J with for me a somewhat “simple” statistics query, and I see his result run of that query on a vault I can only dream of.

My point is; we’re all learning one way or another, so keep on trying and keep on moving ahead!

1 Like

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