I’m trying to display the total number of files (inside of an specific folder (e.g.: Library) and with an specific tag (e.g.: #Book)) created during the last month. Something like: “In the last month you have added [insert number] books in this library.”
Things I have tried
I’m just a newbie with all the stuff related with JS, but I’ve tried to get the total number of books added in April (for example) with this inline JS that I got somewhere:
`$= dv.pages('"Library" and #Book').filter(page => new Date(page.file.created).getMonth() === 3).length`
For some reason it displays “0” (I actually added some books during that month) but either way I’m not looking for an specific month. This is for a dashboard, so I’d like to display the number independently on the month we are.
Is there a solution?
In case it helps, every book contains the following inline field:
That date format is not a recognised date format. Dataview is particular about which format it accepts, and that is the YYYY-MM-DDTHH:mm format when including hours and minutes.
So you’re trying to create a date based upon a “non-date” field, and that just doesn’t work.
The proper way to solve this is to start using a proper date format (aka ISO8601, as shown above), or do some date mangling using moment.js to parse your date-string into a proper date, or to do some regex-trickery to lift out the month from your date-string.
In the last month you have added `$= dv.pages('"Library" and #Book').filter(page => new Date(page.file.cday).getMonth() === 3).length` books in this library.