Noob question about a daterview floating date range date(today) to date(today+30days)

What I’m trying to do

I am trying to create a dataview query that limits the results to files from today to an arbitrary day in the future, such as 30days

But unlike all my previous static dataview queries I want this to be dynamic. So the query tracks from the real date(today) to date(today + x days)

Linux user

I use Linux, so the cdate & mdate will give the wrong date. To get round this, I have “fdate: YYYY-MM-DD” in my frontmatter

Literals, durations and bears oh my

Doc on this

From reading that

I’d guess it would look something like this…

LIST
FROM ""
WHERE file.fdate >= date(today) AND file.fdate <= (date(today)+dur(30 d))

No joy - I’m missing something basic

Normally I use templater and have it automatically fix the date range, like this

TASK
FROM ""
WHERE completion >= date(*templater snippet*) AND completion < date(*templater snippet*)

But that is static

I’ve been searching on the forum, web and docs but I think as this question is very noob it is assumed you would know the syntax

Any help appreciated
Thanks
wintermute_obs

Also did not work with the following

fdate:: 2024-08-23
date:: this.fdate

LIST
FROM ""
WHERE file.fdate >= date(today) AND file.fdate <= date(today) + dur(7d)

or

LIST
FROM ""
WHERE date >= date(today) AND date <= date(today) + dur(7d)

Thanks

Wild and drunken guess:

```dataview
TABLE
date(fdate)
FROM ""
WHERE fdate
AND date(fdate) - date(today) <= dur(30 days)
OR date(fdate) = date(today)
```

Worth a shot I’ll give that a try.

Thanks Hampton

If you’re using date(today) it’s always going to be looking at today, so you should theoretically have no files that were created 30 days from now since that date hasn’t happened yet. So are you actually replacing date(today) with a specific date and you want to look 30 days from that static date or am I missing something obvious?

I use this query to look at a rolling 30 days in the past:

TASK 
WHERE status = "w" 
WHERE file.day > date(now) - dur(30 days)
SORT cdate ASC

Hi Lindsayreads,

I have daily notes in the calendar plugin.

In the future daily notes I have tags for events I need to see, like appointments

i wanted the dataview to look forward through the notes to show me the next 30 days from the real actual now.

I don’t want fixed dates but the from and to date to move as the actual outside world date changes.

Hope that helps.
I see how timetravel is so difficult as this is hard to express :slight_smile:

thanks

If your property fdate already is in Date format, your WHERE clause should look something like this:

WHERE fdate >= date(now)
WHERE fdate <= date(now)+dur(30 d)
1 Like

Thanks Mephi and Lindsayreads,

Solution was using the date(now) format with “<=date(now)=dur(30 d)” and confirming date was in date format in YAML

Snippet that works in my vault

TABLE day, time, appointment, location
FROM "Calendar/daily" AND #appointment 
WHERE fdate >= date(now) AND fdate <= date(now)+dur(30 d)

Example working snippet for normal vault

date: YYYY-MM-DD is in YAML, in date format

TABLE 
FROM "" AND # 
WHERE date >= date(now) AND date <= date(now)+dur(30 d)

Durations

For anyone else looking into this you can look up the “Durations” (Lengths of time Dataview can use to calculate dates from date now) in the below doc. Then plug it into this snippet

Dataview durations

Most of my dataview queries are generated in fixed way through Calendar plugin with set dates.

Useful for fixed notes

This above solution is useful if you have a static page such as “Up Coming Events” which will update to show important stuff coming up based on when your looking at the note, not when it was created.

Thanks all
Obsidian Forum for the win!

1 Like

You’re welcome.
Mind that with your files already being named by date you could even clean up and get rid of the fdate property at all by using the following.

WHERE date(file.name) >= date(now) AND date(file.name) <= date(now)+dur(30 d)

That is handy, Mephi, thanks

WHERE date(file.name) <= date(now) AND date(file.name) <= date(now)+dur(30 d)

Makes me question if I’m using too many un-needed YAML dates.

I have been putting lots of individual YAML date types in my notes. So I can filter dataview quires by weeks or quarters.

I started doing this as cdate and mdate did not work on my Linux set up

Could they all be simplified for notes with the YYYY-MM-DD format in title?

Currently have

year: <% tp.date.now(“YYYY”) %>
date: <% tp.date.now(“YYYY-MM-DD”) %>
quarter: <% tp.date.now(“[YYYY-[Q]Q”) %>
month: <% tp.date.now(“YYYY-MM”) %>
week: <% tp.date.now(“YYYY-[W]ww”) %>
dyear: <% tp.date.now(“DDD”) %>

I guess my question is…

Can I use this date(file.name) and convert it to a week or a quarter etc for filtering dataview quieries?

So instead of using this old dataview query, that uses file.quarter

Highlights this quarter

```dataview
LIST
FROM #highlights  
WHERE quarter = this.file.quarter 

could I instead do…
The following is made up nonsense. Don’t look if easily offended!

```dataview
LIST
FROM ""
WHERE date(file.name, "YYYY-Q") = this.file.date(file.name, "YYYY-Q")

Thanks

Hi again… First of all I’d recommend opening a new thread for a new question, for this one is already marked as solved.

Furthermore you’d likely find a solution by having a short read here:
https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata/#date

In fact dataview plugin already has built-in functionality which would only require a bit mathematical effort on resolving the quarter task. Week of year, e.g. should be easily accessed by following:

date(file.name).weekyear

Cheers

1 Like

Given that either the file name contains an ISO date, or a field like date: YYYY-MM-DD then it’s accessible in Dataview through file.day. And if you want extra dates in other fields I always use that format, as it displays according to locale rules (or date formatting if I want something special), and it allows for extraction of the different parts thorough stuff like fdate.year or similar.

In short, given the ISO date format of YYYY-MM-DD you are very free to do a lot of stuff without to much hassle.

1 Like

Thanks all

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