Dataview from String to Date

Things I have tried

What I’m trying to do

I use the following yaml header.

creation_date: <% tp.file.creation_date() %>

to store the creation date independend of the OS informations.
Noww, i want to use this variable as date in any dataview queries.

The problem typeof(creation_date) = String, which means i can not use if with other date operators like =,<, etc.

Is there any way i can convert a string (with a specified format) back to a date?

Thx

First thing to clarify: what’s the format of the “date” string? YYYY-MM-DD?

No, unfortunately not. A yaml field in format YYYY-MM-DD is considered as date, in my tests. The format is 2022-09-06 15:07

Dataview only recognize ISO dates format. In your case you add a time but don’t follow the right syntax
https://blacksmithgu.github.io/obsidian-dataview/data-annotation/#field-types

To be recognized as a “date-time” iso format needs to be something like YYYY-MM-DDTHH:mm (2022-09-13T10:42)

You have two ways:

  1. you found a way to define in templater an output with the “T” (sorry I don’t know Templater)
  2. you need to transform that string in a date (building a date via dataview code

For second choice, something like

TABLE cDate
WHERE creation_date
FLATTEN date(split(creation_date, " ")[0] + "T" + split(creation_date, " ")[1]) AS cDate

O man, i already read a lot of your great solutions.
Wanted to ask how to create such a date in dataview code and BAM, you pushed the solution for this.

Your a legend, thx a lot

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