In trying to learn a bit more about DQL and specifically about date math in DQL, I built myself a table that shows the progress of the day, week, month, quarter, and year. I thought I would share that here in case anyone is interested.
I was inspired by the Year Progress bots in Mastodon as well as this site. It wasn’t so much that there was anything wrong with those. It was more that the geek in me started to wonder if I could do it.
Also, I suspect there are more efficient ways to do this, perhaps in DataviewJS (I’m very much a beginner with JS and DataviewJS), so if there are suggestions on how to do that, please help me refine this.
I tried posting each of the sections separately, but I hit the character limit for posting. Happy to post them into the comments in a slightly more readable format if there’s interest.
In display mode, the table renders as:
The code for the table is:
| Period | Value | Day | Of | Progress | Percent |
|:-------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Day | `= dateformat(date(now), "EEE, dd-MMM-yy")` | `= dateformat(date(now), "HH")` | 24 | `= "<progress max=" + 24 + " value=" + number(dateformat(date(now), "HH")) + "> </progress>"` | `= round((number(dateformat(date(now), "HH")) / 24)*100) + " %"` |
| Week | `= dateformat(date(now), "kkkk-'FW'WW")` | `= dateformat(date(now), "E")` | 7 | `= "<progress max=" + 7 + " value=" + number(dateformat(date(now), "E")) + "> </progress>" ` | `= round((number(dateformat(date(now), "E")) / 7)*100) + " %"` |
| Month | `= dateformat(date(now), "MMMM '('MM')'")` | `= dateformat(date(now), "dd")` | `= dateformat(date(eom), "dd")` | `= "<progress max=" + dateformat(date(eom), "dd") + " value=" + number(dateformat(date(now), "dd")) + "> </progress>"` | `=round((number(dateformat(date(now), "dd")) / number(dateformat(date(eom), "dd")))*100) + " %"` |
| Quarter | `= choice( (date(now) > date(2023-01-01)) AND (date(now) < date(2023-03-31)), "Q1", choice( (date(now) > date(2023-04-01)) AND (date(now) < date(2023-06-30)), "Q2", choice( (date(now) > date(2023-07-01)) AND (date(now) < date(2023-09-30)), "Q3", choice( (date(now) > date(2023-10-01)) AND (date(now) < date(2023-12-31)), "Q4", "ERROR" ) ) ) ) ` | `= choice( (date(now) > date(2023-01-01)) AND (date(now) < date(2023-03-31)), (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-01-01), "ooo"))+1), choice( (date(now) > date(2023-04-01)) AND (date(now) < date(2023-06-30)), (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-04-01), "ooo"))+1), choice( (date(now) > date(2023-07-01)) AND (date(now) < date(2023-09-30)), (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-07-01), "ooo"))+1), choice( (date(now) > date(2023-10-01)) AND (date(now) < date(2023-12-31)), (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-10-01), "ooo"))+1), "ERROR" ) ) ) ) ` | `= choice( (date(now) > date(2023-01-01)) AND (date(now) < date(2023-03-31)), (number(dateformat(date(2023-03-31), "ooo")) - number(dateformat(date(2023-01-01), "ooo"))+1), choice( (date(now) > date(2023-04-01)) AND (date(now) < date(2023-06-30)), (number(dateformat(date(2023-06-30), "ooo")) - number(dateformat(date(2023-04-01), "ooo"))+1), choice( (date(now) > date(2023-07-01)) AND (date(now) < date(2023-09-30)), (number(dateformat(date(2023-09-30), "ooo")) - number(dateformat(date(2023-07-01), "ooo"))+1), choice( (date(now) > date(2023-10-01)) AND (date(now) < date(2023-12-31)), (number(dateformat(date(2023-12-31), "ooo")) - number(dateformat(date(2023-10-01), "ooo"))+1), "ERROR" ) ) ) ) ` | `= choice( (date(now) > date(2023-01-01)) AND (date(now) < date(2023-03-31)), "<progress max=" + (number(dateformat(date(2023-03-31), "ooo")) - number(dateformat(date(2023-01-01), "ooo"))+1) + " value=" + (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-01-01), "ooo"))+1) + "> </progress> ", choice( (date(now) > date(2023-04-01)) AND (date(now) < date(2023-06-30)), "<progress max=" + (number(dateformat(date(2023-06-30), "ooo")) - number(dateformat(date(2023-04-01), "ooo"))+1) + " value=" + (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-04-01), "ooo"))+1) + "> </progress> ", choice( (date(now) > date(2023-07-01)) AND (date(now) < date(2023-09-30)), "<progress max=" + (number(dateformat(date(2023-09-30), "ooo")) - number(dateformat(date(2023-07-01), "ooo"))+1) + " value=" + (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-07-01), "ooo"))+1) + "> </progress>", choice( (date(now) > date(2023-10-01)) AND (date(now) < date(2023-12-31)), "<progress max=" + (number(dateformat(date(2023-12-31), "ooo")) - number(dateformat(date(2023-10-01), "ooo"))+1) + " value=" + (number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-10-01), "ooo"))+1) + "> </progress>", "ERROR" ) ) ) ) ` | `= choice( (date(now) > date(2023-01-01)) AND (date(now) < date(2023-03-31)), (round(100*(number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-01-01), "ooo"))+1)/(number(dateformat(date(2023-03-31), "ooo")) - number(dateformat(date(2023-01-01), "ooo"))+1))) + " %", choice( (date(now) > date(2023-04-01)) AND (date(now) < date(2023-06-30)), (round(100*(number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-04-01), "ooo"))+1)/(number(dateformat(date(2023-06-30), "ooo")) - number(dateformat(date(2023-04-01), "ooo"))+1))) + " %", choice( (date(now) > date(2023-07-01)) AND (date(now) < date(2023-09-30)), (round(100*(number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-07-01), "ooo"))+1)/(number(dateformat(date(2023-09-30), "ooo")) - number(dateformat(date(2023-07-01), "ooo"))+1))) + " %", choice( (date(now) > date(2023-10-01)) AND (date(now) < date(2023-12-31)), (round(100*(number(dateformat(date(now), "ooo")) - number(dateformat(date(2023-10-01), "ooo"))+1)/(number(dateformat(date(2023-12-31), "ooo")) - number(dateformat(date(2023-10-01), "ooo"))+1))) + " %", "ERROR" ) ) ) ) ` |
| Year | `= dateformat(date(now), "kkkk")` | `= number(dateformat(date(now), "ooo"))` | `= number(dateformat(date(2023-12-31), "ooo"))` | `= "<progress max=" + (number(dateformat(date(2023-12-31), "ooo"))) + " value=" + (number(dateformat(date(now), "ooo"))) + "> </progress>"` | `=round(100*(number(dateformat(date(now), "ooo")) / number(dateformat(date(2023-12-31), "ooo")))) + " %"` |
Sorry for the very long scroll … the math for the quarters got a bit out of hand.