{{date}} not returning today's date in templates

Hello,

I’ve been unable to find a solution for this in search, despite finding a few other issues with {{date}} and properties, but if it is a known issue I apologise and please point me to a solution! I believe I’ve followed all the troubleshooting.

I’m trying to use a template that has a property called created, which populates with today’s date when I apply the template. I have a template (core plugin only) and in the template, in source mode, I have:


created: {{date}}

which I thought would create today’s date, but when I apply the template to a new note I get the date 20/11/2003 … so, definitely not today. And not the current date on my system.

This issue is happening with all community plugins off (restricted mode), but doesn’t happen in the test vault.

If this isn’t a bug and I’m misunderstanding something, again I apologise. Hope someone can help - thanks!

Debug info:
SYSTEM INFO:
Obsidian version: v1.4.16
Installer version: v1.4.16
Operating system: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6020 22.6.0
Login status: logged in
Catalyst license: none
Insider build toggle: off
Live preview: on
Legacy editor: off
Base theme: light
Community theme: none
Snippets enabled: 0
Restricted mode: on

RECOMMENDATIONS:
none

What do you use as a format for the date in the Template core plugin :blush: ?

1 Like

It may be misplaced, but there is a problem with the following format description or …

Templates - Obsidian Help

You can change the default date and time formats under Settings → Templates → Date format and Settings → Templates → Time format .

This is what I’m seeing in the Templates core plugin, which looks like it should return the correct date?

1 Like

The DD-MM-YYYY format you used in the settings of the Template core plugin will return today’s date… but not in Properties … At least, not for a date or date & time type of key :blush: .

I think that you’re probably running into an issue similar as this one: Properties: Change from "text" to "date&time" rewrites day and year. Month and time unaffected :blush:

When a date or date/time is written on file in YAML (when you create a note/apply a template) for date or date/time type of keys, the only format allowed for this to work correctly when the date or date/time is later on parsed and displayed in Properties is the ISO8601 format (YYYY-MM-DD).

See: Properties: let the user customize the way Dates/Times are saved

In other words, in this case, Properties can’t correctly read the format you used in source mode/YAML and mixes it up when it displays it in Live Preview/Reading mode :blush: .

E.g.: Yesterday was 2023-11-03 which was written/saved as 03-11-2023 in YAML/source mode.

When parsed to be displayed in Properties:

  • DD03 → becomes the year part → 2003

    • (There is/was (?) a truncated way to represent years in ISO where the century is implied (YY-MM-DD) so I can only guess that Properties assumed this is what was used here)
  • MM11 → is still the month part → 11

  • YYYY2023 → becomes the day part → 20

    • (I guess that only the first 2 digits are taken in account here)
  • … which results in Properties (when in Live Preview/Reading mode) → 20-11-2003

A workaround, if you don’t want to change the date format in the Template core plugin so you can use it as it is outside of YAML/Properties (with the {{date}} placeholder), would be to use, in your template, something like :

---
created: {{date:YYYY-MM-DD}}
---

… to bypass the format set in the settings and use the ISO one instead in YAML/Properties :blush: .

2 Likes

Thank you so much, @Pch ! I really appreciate you explaining what was going on :blush: I’m still new-ish to Obsidian and not aware of all the underlying rules and principles of how things work, thanks for helping me grasp what was going wrong.

I’ve used your workaround and it’s working as expected now – I’m no longer in 2003 :sweat_smile: (or 2004, as of today). :pray:t2:

2 Likes

My pleasure :wink: !

I’m very glad to know you’re now back with us in the Present :smile: :raised_hands: !

1 Like

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

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