Date formatting mess

What I’m trying to do

Trying to define and use a single format for dates.

Things I have tried

Today is August 23, 2024, or 2024-08-23 in the ISO style, or 08-23-2024 in the US fashion, or 23/08/2024 in the French manner. I am testing date formats in a Property (frontmatter) and an inline field.

Settings

  • My OS (Windows) is (automatically) set to the French standard: DD/MM/YYYY.

  • I have set the same DD/MM/YYYY format in the Template and Daily Note plugins (although this should not be relevant as I am not using those plugins).

  • I have not found any other place in the Obsidian settings where the date format could be globally defined.

  • Dataview - 1st try: same DD/MM/YYYY format with the following result:

  • Dataview - 2nd try: dd/mm/yyyy with the following result (the month number changes everytime I check, even into “41” or “00”…):

  • Dataview - 3rd try: I managed by chance to get the correct result by simply typing a “D”:

Results in a note

image
image

  • The Date property shows DD/MM/YYYY in view mode, but YYYY-MM-DD in source mode.
  • An inline date field will only be recognized by dataview if formatted as YYYY-MM-DD. Failing this is understood as a string.
  • Therefore, it seems that the user-defined format is not taken into account.

Results in a dataview query

Is this a native mess, or am I doing something wrong?
Thanks for your help!

1 Like

I’m having the exact same issue. Formatting it in any way with the year brings up two extra numbers, will update if I figure it out as well

Okay, so it seems as though in the first example, YYYY is just coming out as YYYY and not the actual year, MM is either coming out as the correct month or 00, and DD is coming out as the whole date, so when it is put together, you get the whole date plus 08/00 and YYYY.

The solution that has worked for me is to use “yyyy-MM-dd” - the month stays the same, but DD and YYYY should be lowercase. Hope that works for you!

It does! - although it seems that this is just a display format. Behind the scene, dataview converts it into, and works with “yyyy-mm-dd”. And dataview is unable to understand the custom format in an inline field: “28/08/2024” is considered a string…

This means that inline date fields (data, as opposed to frontmatter metadata) must be input in the “yyyy-mm-dd” format. As stated in Data Types - Dataview (blacksmithgu.github.io): “Text that matches the ISO8601 notation will be automatically transformed into a date object”. Meaning, any other notation won’t work.

Therefore (and this was my main grip), there seems to be no way to display an inline date field in the user-defined format… or is there one?..

For Dataview to natively understand a field like a date it needs to be in the ISO 8601 format. However, you’re able to convert some text strings into dates using the date(text, format) function.

This would allow you to specify the inline field as you like it, and still convert it into a date when you need to.

Problem solved, thank you!

TABLE WITHOUT ID file.name as Asset, Date, Vendor
FLATTEN date(Date, "dd/MM/yyyy") AS Date
SORT Date ASC

Now, the string in the inline Date field is actually converted into a date, which makes it sortable:

Asset(2) Date Vendor
Thing 25/07/2023 Amazon
Stuff 02/04/2024 Ebay

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