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.
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:
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:
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.
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.
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.