Dataview get remove Time from Date

Hi there, in my frontmatter I automatically get ‘created’ and ‘updated’ fields with the format ‘2022-03-16T20:20:18+01:00’

I wanted to add a overview over all notes I modified on a day in its daily note, but since I am syncing my vault via git, the file variables cday and mday might not be correct.

  • I am using dataviewjs because I wasn’t familiar with either and it read as if it was the mightier tool.

I can format dates and times into the same format with the date() -function?, but I obviously don’t want to compare seconds but onyl full days. I haven’t found a way to get only a YYYY-MM-DD format without the time.

I guess I could query the date for each one (year, month, day) and put it back together, but I’m sure there is a better way.

Dates

You can retrieve various components of a date via indexing: date.year, date.month, date.day, date.hour, date.minute, date.second, date.week. You can also add durations to dates to get new dates.

For the normal dataview query I found the dateformat(), but it seems it is not available in dataviewjs ?

What I’ve tried

1.
`$=dv.date(dv.current().updated).month`
2.
 `$=dv.current().updated`
3.
 `$=dv.current().file.cday`
4.
 `$=dv.date(dv.current().updated).equals(dv.current().file.cday)`

Which gets me

1. 3
2. 8:20 PM - März 16, 2022
3. März 16, 2022
4. false

I’ve also found luxon/formatting.md at master · moment/luxon (github.com), but before I mix/msh queries I have no idea about, I wanted to ask.

Hi.
Two points:
1 - You want a list of modified files in your daily notes? But that list isn’t stable, because dataview results are dynamic and in any update of your notes they are removed from your daily note query results.
2 - You’re right, in dql queries you can use dateformat(). My knowledge of js is almost zero. But I extract from others js queries in the Forum this expression: $=moment().format("YYYY-MM-DD") (for date(now)). Applied to your case, you can try this:

`$=moment(dv.current().updated).format("YYYY-MM-DD")`

1 - That is a good point, I would only have the list “correct” for the last day I worked on that file, which is fine for now since I mostly want to use it to not “loose” some topic.

I can only see two ways of handling that

  • track each modification (in frontmatter for example)
  • try to make a static list of the dynamically rendered list at the end of the day (or beginning of the next) - but I don’t know of any tool for that.
  1. That is helping a lot!

I’m trying to adjust this table

// default dateformat in case it’s forgotten in front matter
var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }

dv.table(["File", "Last Modified", "Date Created"],
  dv.pages()
  .where(p => p.file.mday.equals(dv.current().file.cday) || p.file.cday.equals(dv.current().file.cday))
  .sort(p => p.file.mtime, 'asc')
  .map(p => [
    p.file.link,
    moment(p.file.mtime.toString()).format(dateformat),
    moment(p.file.ctime.toString()).format(dateformat),
  ])
);

To use my updated and created frontmatter as well as the title (rare case I’m creating a daily note not on the day its about).

have to stop my post and thoughts here… I’ll be back with a question ^^

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