Dataview to highlight columns if "Deadline" is today's date?

What I’m trying to do

I have a simple dataview table:

table Deadline
FROM [[⛰️ Admin]] and #🚧/🟨 
SORT Deadline asc

Output:

I’d like to format the table such that if a given column has Deadline equal to today’s date (in format YYMMDD), then that entire column is highlighted in some color, or stands out in some obvious way.

In this case, I’d like the first column in the table above to be highlighted because Deadline == 230331, which is today’s date in YYMMDD format.

Things I have tried

I’ve tried searching the forum for a similar topic but I’ve come up dry, and don’t know enough about scripting / dataview to try anything fruitful.

Please help! Thanks!

EDIT: Spelling / Grammar

There are two sides to this request, firstly how to get your date looking field to be an actual date, and then how to format cells related to comparisons based upon that date field. For the latter part, see this answer.

For the first part, you’ve got two options, and that is either to switch to a proper date format like YYYY-MM-DD which is interpreted as a date by default, or you’ve got to transform your text into a date.

Something like the following should work to transform it into a date (although I would strongly consider to change into a proper date format):

```dataview
TABLE Deadline, deadlineDate
FLATTEN date( regexreplace(Deadline, "(\d{2})(\d{2})(\d{2})", "20$1-$2-$3") ) as deadlineDate
FROM [[⛰️ Admin]] and #🚧/🟨 
SORT Deadline asc
```

And if combined with the CSS stuff from the other answer, you could get a somewhat more complex query like the following:

```dataview
TABLE
  "<span class='" + cellClass + "'>" + deadlineDate + "</span>" as Deadline
FROM [[⛰️ Admin]] and #🚧/🟨 
FLATTEN date( regexreplace(Deadline, "(\d{2})(\d{2})(\d{2})", "20$1-$2-$3") ) as deadlineDate
FLATTEN 
  choice(deadlineDate > date(now), "cellOK",
   choice(deadlineDate =  striptime(date(now)), "cellWARN",
    choice(deadlineDate < date(now), "cellLATE", ""))) as cellClass
SORT deadlineDate asc
```

Which with (almost) the same data as you presented in your image, would produce something like:

PS! Mouse insurance?! Why do you insure your mice?! And from what? :smiley:

Thanks for the reply!

I’m running into some trouble - I’d like to keep my date format as YYMMDD, since I have hundreds of files in that format and changing it would be painful.

That being said, if I paste the first dataview query you cite in your reply into my vault, I get the following error:

“Dataview: Unrecognized query operation ‘binaryop’”

Any ideas what’s going on here? I’ve searched this forum and can’t seem to figure it out.

Thanks very much for the help thus far!

Yeah, it’s me being stupid. Switch the order of the FROM and the FLATTEN line.

To my excuse, I used a WHERE clause in my tests, and then the order was correct… :upside_down_face:

Right, I thought so!

You’ll understand my surprise when I still get an error, switching the order of the FROM and the FLATTEN line:

"Dataview: Every row during operation ‘flatten’ failed with an error; first 3:

  • No implementation of ‘regexreplace’ found for arguments: number, string, string
  • No implementation of ‘regexreplace’ found for arguments: number, string, string
  • No implementation of ‘regexreplace’ found for arguments: number, string, string"

It’s those tiny differences when one don’t have the same files to work with. Try exchanging Deadline with string(Deadline) within the regexreplace().

(If we had full access to div and mod, you could theoretically do div and mod to split up your number, but I think that would possibly look a lot worse)

Great, that fixed the first query from complaining!

Haha. Now for the second query.

Using the following:

TABLE
  "<span class='" + cellClass + "'>" + deadlineDate + "</span>" as Deadline
FROM [[⛰️ Admin]] and #🚧/🟨 
FLATTEN date( regexreplace(string(Deadline), "(\d{2})(\d{2})(\d{2})", "20$1-$2-$3") ) as deadlineDate
FLATTEN 
  choice(deadlineDate > date(now), "cellOK",
   choice(deadlineDate =  striptime(date(now)), "cellWARN",
    choice(deadlineDate < date(now), "cellLATE", ""))) as cellClass
SORT deadlineDate asc

and after following the cellColor.css instructions in your linked answer, I get as output exactly the same table as before. No highlighting or any difference whatsoever.

Any ideas?

Do you see your css snippet in Settings > Appearance > CSS Snippets, and it’s enabled?

If not you might need to change the file extension to be .css (instead of the usual .md). Or if you don’t see it at all you need to move it into the correct folder.

Yep, I do see it there.

image

Hmm… Then what is happening… Could you copy back the CSS in a codeblocks here? Is it the same in both reading view, and live preview?

Are you able to to check the Developer Tools, and see that the table is tagged with the </span class="cellOK"> stuff?

Are you running some theme which interferes?

And maybe the best tip, could you do “Show debug info” to show Obsidian version, and especially the installer version which needs to be at least 1.0.9.

UPDATING THE INSTALLER FIXED IT!

Thanks so much, lol.

1 Like

Last thing: Do you know of a way to get the entire row highlighted, and not just the Deadline column?

Thanks so so much for the help hitherto.

Yeah, just change the td in the Css to become tr.

1 Like

Thanks!

Sorry, one more question on this topic.

Since this change, by vault becomes sluggish for about half a second while dataview is refreshing changes.

Do you think this is because of my date format being reinterpreted, or because of the date comparisons it’s doing to provide those highlights?

Thanks!

Hard to tell, but this shouldn’t be that much to progress. It would be simpler with a better date format, but you shouldn’t really notice either way.

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