Dataview incorrectly displaying date from YAML

What I’m trying to do

I’m attempting to have a date created in the YAML of a file appear in a table via Dataview.

For some reason, using normal iso date format, I’m receiving a “00” in my MM category.

image

image

Things I’ve Tried

I noticed that when I change my date format from “YYYY-MM-DD” to “YYYY-M-DD”

It will populate a “1” correctly for January for example…

But if put back into “YYYY-MM-DD” it returns the same 2023-00-28

Any help would be appreciated!

I just tested with <%+ tp.date.now("YYYY-MM-DD") %> which will render when going to reading view, and it does indeed produce the (almost) expected 2023-01-29 (Oh… Is it past midnight already! Bummer… I thought I still was on the 28th… ).

If it doesn’t do that for you, I would check for updates in the plugins, and restart Obsidian and see if it persists on doing the wrong thing.

@holroy - thanks for your speed - issue is persisting on my side.

image

Noteably - Any single digit month date is procuring the same issue - I’m able to get the actual “date” inside any file, but as soon as I attempt to dataview it in another file, the dataview is not properly displaying the date.

What do you get if you do this query:

```dataview
TABLE WITHOUT ID file.link as "Name", dateformat(date, "yyyy-MM MMM") as "Date", file.frontmatter as "Frontmatter"
FROM #f53334
SORT file.name desc
limit 3
```

In a simple test setup of mine, I get this:

1 Like

Great help!

After playing around with this - this is what I found if I use dateformat(date, “yyyy-mm-dd”) it will work. But if I use capital MM it will not.

I believe that there is some issue with formatting here as this is an unexpected result.

See here for the documentation on dateformat: Functions - Dataview

This uses luxon tokens, so “yyyy-MM-dd” should be the correct variant for dateformat to get 2023-01-29. (Using “mm” should return the minutes with two digits)

Also be aware that Templater uses the tokens from moment.js, so for its dateformats it would be “YYYY-MM-DD”. See Moment.js | Docs

1 Like

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