cablo69
September 13, 2022, 1:55pm
1
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
mnvwvnm
September 13, 2022, 2:00pm
2
First thing to clarify: what’s the format of the “date” string? YYYY-MM-DD?
cablo69
September 13, 2022, 2:04pm
3
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
mnvwvnm
September 13, 2022, 2:08pm
4
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:
you found a way to define in templater an output with the “T” (sorry I don’t know Templater)
you need to transform that string in a date (building a date via dataview code
mnvwvnm
September 13, 2022, 2:10pm
5
For second choice, something like
TABLE cDate
WHERE creation_date
FLATTEN date(split(creation_date, " ")[0] + "T" + split(creation_date, " ")[1]) AS cDate
cablo69
September 13, 2022, 2:12pm
6
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
system
Closed
September 20, 2022, 2:12pm
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.