Struggling to change linked date format in dataview query

What I’m trying to do

For various filing, sorting, and search reasons, I have an elaborate and redundant Daily Note date format (YYYY.MM.DD - ddd, MMM Do, YYYY), but I don’t want that to show up in a dataview table. I’m trying to use dateformat to customize the date in links to the individual notes, but for some reason, I just can’t get it to work.

This:

TABLE WITHOUT ID 
	link(file.link, dateformat(Date, "MMM dd")) as Date
FROM "Writing/Journal"

Completely ignores MMM dd and any other formatting string I try. It continues to issue my elaborate format (the link works, however).

What am I missing?

That text string is not treated as a date, so you need to get it back to being a date, and then format it. So maybe something like: dateformat( date(substring(Date, 0, 10), "yyyy.MM.dd"), "MMM dd"). A little unsure if the substring is correct, but the idea is to pick the fully qualified part, and then use date(text, format) on it to build a date, and then format is to whatever format you’d want.

Another idea, if the format is already present in there, at a fixed place, is to just use substring(Date, a, b) replacing a and b with the correct locations minus 1.

Lastly, if it’s not fixed place but with given anchors around it, you could also use regex to pick out the interesting part. I’m not going to type it out, as most likely the first variant is easier to comprehend.

Both the last variants require the text you want to output to be present already in the string at hand.

Unfortunately, neither of those solutions seems to work with my example. They’re still giving me my elaborate default format. It’s like dateformat is ignored entirely, which I suppose may imply something about using file.link the way I am, but I didn’t know how to apply links to the dates without it.

Is there something I might try other than dateformat (or file.link, as the case may be) because it just doesn’t seem to be working in the context I’ve got it in.

Do you have Date as a property 26th that elaborate date format? Or do you only have that as a file name? If the latter, you’ll need to use file.name instead of Date.

What do you use to generate that format? Templater? Could you show todays date in your format, so I can have an example to test with? (Both of the original variant, and the target that you want)

The elaborate date is my setting for the Daily Notes core plugin, so I guess it’s just the file name I’m working with? The full setting is YYYY/MM/YYYY.MM.DD - ddd, MMM Do, YYYY, which sorts my daily notes in year/month folders and gives me a couple of easy-to-search options from the file name/title.

I did actually try working with file.name, as well, but I couldn’t figure out how to cleanly alter the date that way at all.

Thanks for trying to help. :slight_smile:

First, your custom date isn’t a date anymore, so dv won’t recognize your date as a date.

Second, check if your note name is displayed as inline title:
settings>appearance>interface>show inline title and deactivate.

Does the code below do what you need? It ‘works’ in a local vault.

```dataview
TABLE WITHOUT ID 
dateformat(date(substring(file.name, 0, 10), "yyyy.MM.dd"), "MMM dd") AS Date
, link(file.name, dateformat(date(substring(file.name, 0, 10), "yyyy.MM.dd"), "MMM dd")) As Link
FROM "Writing/Journal"
```

1 Like

This was what I was eluding at with my earlier posts, or variations over this theme. I was a little unsure on how your file names looked, and the OP indicated that they possible had Date as a property.

But given that it’s not a property, this is indeed the way to query this and reformat the date in just for display purposes (as in the second column) or as a link with an aliased text.

1 Like

This worked perfectly. Thank you so much!

1 Like

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