Dataview + Tasks: query HH:mm in a task's description

Things I have tried

I have searched the forum and the internet several times but I cannot find how to achieve what I want

What I’m trying to do

  • I have a Daily Note (created from the Periodic Notes plugin) and a template for it
  • In the template I have dataview queries for today’s tasks (works fine)
  • In the template I also have a section where I want to show tasks with an HH:mm timestamp as the beginning of the task’s description, because I cannot find how to add a due TIME in the Tasks plugin. Is there a way that I am overlooking?
  • So now I need a way to have dataview show me only those tasks that have this HH:mm and I cannot figure out IF it can do that and if so, HOW…
  • …but I think that @Moonbase59 will know or another of you dataview(js) wizards :blush:

I want this to distinct non time sensitive tasks from ones that are really due at a certain time on their due date. Like ToDo versus Agenda.

1 Like

This I can guess at more quickly than calendar locales (which I am still stumped on)!

  • I am pretty sure Tasks does not support due times but that there is probably a GitHub Discussion requesting it if you want to upvote more things!
  • I am not very expert at regular expressions, but a website helped me come up with one that matches starting a line with 2 numbers then a colon then 2 numbers. So it will match on invalid times like 99:99 if you have any tasks starting with that!
  • Dataview recently added lots of implicit fields on tasks, one of which is text, and it also has a function to check for regular expression matches.

Here’s some example code. (Line with FROM optional / probably the same as whatever is in your working query for today’s tasks.)

TASK
FROM #taskTag
WHERE regexmatch("^\d{2}:\d{2}", text)

Notification to @I-d-as who has been excited about regular expressions recently and question to Moonbase and the other long-time dataview wizards - is there a better expression to check for lines that start with “HH:mm”?

2 Likes

Hi @scholarInTraining , thanks for this, I just don’t understand how to write it all out in dataview or dataviewjs…I know what I want but have no clue how to achieve it.

I have this daily note template where I want to have the task with a time on top under the header “agenda” and below that all the other tasks but exclude the tasks with a time. I managed to find out how to exclude! Yeah for me :grin: !

Right now I have this:

{{date: dddd DD MMMM YYYY}} ^top

  • [[#Notities top ⇧|Notities]]

agenda

TASK 
WHERE regexmatch("^\d{2}:\d{2}", text)

todo

TASK 
WHERE regexmatch("^(?!\d{2}:\d{2})", text)

notities [[#^top|⇧]]

I really appreciate your time and effort to help me build the perfect agenda/todo system for this new challenge I am facing - I am going to be the chief editor for a brand new magazine and I want to have a workflow inside Obsidian that I can rely on to make this work with as little hassle as possible. I would like the only other two apps that I need to use, be Gmail and Adobe InDesign (can’t do without those, wish I could mail right from Obsidian haha!)

Could you pls help me with the first dataview to reflect ONLY today’s timed tasks? Right now it lists all the future timed tasks, but I’d like to know how to only view todays, and from there I will probably be able to figure out all timed tasks for this week and month.

1 Like

Wow congrats on the new job @FiekeB - that’s super cool!!!

Could you share your working query you mentioned in the first post that gets “today’s tasks”? I bet we can combine with the stuff here to get what you asked about!

A note on the example in “agenda”: that one is not checking whether the task is un-completed! You can either add a second WHERE line with WHERE !completed or append to the existing WHERE line with AND !completed.

todo
I’ll edit this post if I figure out how to do the call to regexmatch in the Javascript dataviewjs, which I imagine is more intuitive for both of us when we’ve been staring at Javascript recently, but for now does the following work? If not, there might be a problem with my regex.

TASK
WHERE !regexmatch("^\d{2}:\d{2}", text) AND !completed
1 Like

Hi @scholarInTraining, thanks for your remark about my first piece of dataview showing everything instead of only uncompleted tasks! I added your suggestion and it works beautifully.

All I’d need for now, is for that first piece of dataview to reflect/show ONLY today’s tasks and not the ones for past or future. I edited my first post, you may have missed that edit becauseI just edited it. Like a minute or so ago.

I added these lines to that post:

" Could you pls help me with the first dataview to reflect ONLY today’s timed tasks? Right now it lists all the future timed tasks, but I’d like to know how to only view todays, and from there I will probably be able to figure out all timed tasks for this week and month."

@FiekeB We were probably typing/editing at the same time! Could you please share the working query for “today’s tasks” that you mentioned in the first post? I bet we can combine that in!

1 Like

I doubt that, @scholarInTraining, because that wasn’t done with dataview but only a query from the tasks plugin itself…but here it is:


```tasks
not done
due today
short mode

the forum isn’t picking up my closing ``` for some reason but they are in the actual code in obsidian

I have tried the following:

TASK 
WHERE regexmatch("^\d{2}:\d{2}", text) AND !completed
WHERE dueDate >= date(today)

but that does not give any results at all (but at least not an error) - but there IS a timed task for today so that should show. (if the code is correct, of course)

Aha! Bummer that the Tasks plugin doesn’t yet support regex search in task text, though I think they are working on it.
It does help, though, because it tells me that your dataview field for “due” is in fact “due” (thanks to dataview interpreting that emoji from Tasks, see here for which subset of the tasks emoji it supports) and that the value is a date in YYYY-MM-DD format. So we will be adding to the dataview query something with WHERE due = date(...) or in dataviewjs, if either of us figure out how to do the regex part in js, .where(t => t.due == dv.date(...) (should that have 2 equals or 3 equals in JS? I haven’t sorted out that concept yet. Do you know?)

How to get “today” to fill in the … in the date()? An easy way, which I confirmed worked on a Tasks plugin formatted task just now, is to just use the string "today" in place of the .... Then, due today or previously would be:
WHERE due <= date("today") and due previously or within the next 7 days would be WHERE due <= (date("today") + dur("7 days"))
(The function dur turns a string into a Duration and accepts various input formats see here. Durations can then be used for arithmetic with dates. I believe the dataviewjs version of this is Duration("7d") with no dv in front of it.)

A more complicated way to get “today” would be to get it from the title of your note. You’d have to convert the date’s format from whatever format you use to YYYY-MM-DD in order to compare it with the due field successfully. Dataview Query Language (but not dataviewjs) has an undocumented function called dateformat that can help. Example usage: WHERE due <= dateformat(date(...), "YYYY-MM-DD") but this isn’t very helpful unless date() is good at parsing dates of different formats, and I am not sure it is. So I am going to pause on this line of inquiry and hope that the regexmatch is easy to duplicate into JS and we can deal with this in JS.

EDIT: I just saw the bottom of your last post and you were so close! The field dataview turns the due-date-emoji into is called due instead of dueDate

1 Like

Hi @scholarInTraining , thanks for your answer! EDIT: it works great but (of course) only for the actual todays daily note and (of course) not for future daily notes that I create in advance.

I’m guessing we’ll then have to write code that says that “due today” in this case means to look at the filename (which is essentially just a date in the YYYY-MM-DD format) and that the filename then counts as “today”. Edit: I now realize that you also mentioned that ! Going to try now! Edit: tried but I could not get that to work. There is some code referring to the filename,I have seen that on the forum.

Is that explained well enough, or am I unclear? I ama full blown alpha person dealing with language way more than with code…even though that too is considered a “language” in ICT, it doesn’t feel as such to me at all :stuck_out_tongue:

1 Like

Yes I didn’t explain the part well enough. Knowing how your filenames look makes it much easier! And since they are already in “YYYY-MM-DD” format, it is even easier!
Here’s due today, not completed, and NOT matching a time in front:

TASK
WHERE due = date(file.name) AND !completed
WHERE !regexmatch("^\d{2}:\d{2}", text)

and here’s due previously or in next 7 days, not completed, and matching the time at the beginning of the text:

TASK
WHERE due <= (date(file.name) + dur("7d")) AND !completed
WHERE regexmatch("^\d{2}:\d{2}", text)

The regex comparison is more work for your computer than the other queries, so I put it after the others - that way you will have already filtered the tasks to a smaller number before you do the more intensive operation on them.

1 Like

Thanks a bunch, checking this out right now! :blush:

1 Like

Hi @scholarInTraining , I will show you what is in my template and what my experiences are with the code you provided. Something isn’t quite right yet, or I am doing something wrong which is totally possible.

I will first paste my template as it is in Markdown and after that I will paste it the way it looks when rendered. If that is at all possible on the forum. Otherwise I will make and post a screen shot of the rendered version. I did try to change a few things like the order of the “WHERE” etc but that made no difference at all.

{{date: dddd DD MMMM YYYY}} ^top

for today that is

maandag 20 juni 20022

  • [[#notities top :arrow_up:︎|Notities]] :arrow_down:

agenda

the dataview code below gives me all uncompleted tasks for today with a time (HH:mm at the beginning of their description). It will ALSO show all timed tasks with no due date at all. These “no due date timed tasks” don’t make sense of course, so that’s fine, I can then edit the task and give it a due date.

However, if I create a future Daily Note, it will not show the timed tasks for that future day, but only for the actual, literal day of Today.

		```dataview
		TASK 
		WHERE regexmatch("^\d{2}:\d{2}", text) AND !complete
		WHERE due <= date("today")
		```

So I need to make dataview consider the filename as the “today” it should work with, because then it ought to be able to parse out the timed tasks for a future Daily Note, too. My Daily Notes all have a filename that consists of only the date in the format of YYYY-MM-DD.

You came up with this dataview code below, which gives no error, but also doesn’t give any results. And there actually IS a timed task for today. So something here isn’t quite right, yet.

	```dataview
	TASK
	WHERE due <= date(file.name) AND !completed 
	WHERE regexmatch("^\d{2}:\d{2}", text)
	```

todo

the dataview code below gives me all the uncomplete tasks for today WITHOUT a timestamp and ALSO all tasks WITHOUT a due date. Not all tasks need a due date, so I guessthat’s fine, But I would love to know how to skip the “no due date” ones.

	```dataview
	TASK
	WHERE !regexmatch("^\d{2}:\d{2}", text) AND !completed
	```

Trying to change that code to something that will ONLY give us uncomplete tasks WITHOUT a timestamp and only due for today (with “today” being the filename), you came up with the following dataview code:

	```dataview
	TASK 
	WHERE due <= date(file.name) AND !completed 
	WHERE !regexmatch("^\d{2}:\d{2}", text)
	```

But that, to my surprise! skipped precisely the one uncompleted untimed task that was actually due today and instead showed me all the others that had no timestamp nor a due date. While logically (for me at least) I’d say that should work.

notities [[#^top|⬆︎]]


Bother! Our vaults are having different behaviors in response to the same query regarding file.name. I’m going to check manually for Community Plugin updates and restart Obsidian just in case that helps. Another possible investigation strategy would be a temporary table that looks something like this (replacing the string after FROM appropriately):

TABLE WITHOUT ID
file.name AS "name string",
date(file.name) AS "name as date"
FROM "Full/Path/To/Daily/Note/For/Today"

Skip the "no due date"
I’m glad you caught that and oooops for not thinking of it when I was writing my queries! I think AND !due added into the WHERE statements should work.

Will edit if I have any ideas on the rest.

1 Like

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