Dataview dateformat function

The file names for my daily notes use ISO8061 format: YYYY-MM-DD.

At the end of each daily note there is a Dataview query:

```dataview
LIST from "journal" 
WHERE file.day.day = this.file.day.day
AND file.day.month = this.file.day.month
SORT file.name desc
```

It is used to list the day’s daily notes from other years. For example:

2023-02-26
2022-02-26
2021-02-26
2020-02-26
2019-02-26
2018-02-26
2015-02-26
2014-02-26
etc, etc, etc

As each date in the query is a link, I can quickly navigate to see what I was doing on this day in any year that I have a journal entry for.

Ideally, I would like the query to list the dates in cccc, dd MMMM yyyy format, such as Sunday, 26 February 2023.

I think I should be able to use the dateformat function to style the query, but I just can’t get it to work.

Could anyone offer some advice or just tell me (before I am reduced to tears) that it can’t be done?

Oodles of thanks.

2 Likes

Yes, it can be done. :smiley:

And this is how you do it:

### Extended table view of the date and file stuff
```dataview
TABLE file.frontmatter.date, file.day, file.title
WHERE file.folder = this.file.folder
```


## Changed list

```dataview
LIST WITHOUT ID link(file.link, dateformat(file.day, "cccc, dd MMMM yyyy"))
WHERE file.folder = this.file.folder
WHERE file.day.day = this.file.day.day
  AND file.day.month = this.file.day.month 
```

These two queries produce this output:

The first query lists all the test files from my folder, which also shows how Dataview is able to pick up the date from the file name (or for those last two files from the date field in the frontmatter, if you just want to really name your file something entirely else).

Note how your previous file names, also gets picked up.

The last query, shows what you asked for in this request, namely using dateformat() to change the link. Do note that we’ve got to use LIST WITHOUT ID to be able to change the format, so it’s then a little more cumbersome to add other stuff into the list, if that’s wanted.

(I’m kind of thinking one might be able to change the date format in the settings somehow, but couldn’t figure out how to get that to take effect on queries directly)

1 Like

That’s really helpful and really far beyond anything I had come close to achieving.

My daily notes are in yearly folders and monthly subfolders. For example:

journal
> 2023
>> 01
>>> 2023-01-01.md
>>> 2023-01-02.md
>>> 2023-01-03.md etc
>> 02
>> 03 etc
> 2022
>> 01
>> 02
>> 03 etc
> 2021
>> 01
>> 02
>> 03 etc

Because of the folder levels, the Extended table view of the date and file stuff returns files only from the month being queried. For today’s daily note it lists all the daily notes for February 2023.

For the Changed list, it lists today’s daily note in isolation. If WHERE file.folder = this.file.folder is removed from the query, it lists the daily notes for this day in previous years AND it gives the formatting I wanted:

Sunday, 26 February 2023
Saturday, 26 February 2022
Friday, 26 February 2021
Wednesday, 26 February 2020
Tuesday, 26 February 2019
Monday, 26 February 2018
Thursday, 26 February 2015
Wednesday, 26 February 2014

So both of the following work perfectly for my needs:

```dataview
TABLE WITHOUT ID 
link(file.link, dateformat(file.day, "cccc, dd MMMM yyyy")) AS "Previous Years"
WHERE file.day.day = this.file.day.day
  AND file.day.month = this.file.day.month 
SORT file.name desc
```

```dataview
LIST WITHOUT ID 
link(file.link, dateformat(file.day, "cccc, dd MMMM yyyy"))
WHERE file.day.day = this.file.day.day
  AND file.day.month = this.file.day.month 
SORT file.name desc
```

It would have taken me a lifetime and more to write this poetic gem: link(file.link, dateformat(file.day, "cccc, dd MMMM yyyy")), so I am really grateful for your help and kindness.

A huge thank you. :clap:t3::raised_hands::pray:

2 Likes

Sorry, I forgot to remove that statement which I use to limit the searches in my test vault.

You should indeed remove, or replace with something like FROM "journal".

But you do understand and see how flexible it is to use the file.day in relation with either a proper date in the file name, or through the use of the date field, right?

The entirety of the first query was designed to showcase the filenames versus file.day, and to show which files I used also for the second query.

1 Like

I am trying to. :rofl: Reading and learning and trying and admiring …

1 Like

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