Create progress bar with custom dates

Hello everyone,

I’m relatively new to obsidian and have been trying to create a simple progress bar that shows current date as progress between 18 may 2023 and 18 may 2024.

Does anyone have a simple solution for this?


There is probably a simpler way, but I found this which works well and also displays the percentage and the number of days:


var a = moment("2023-05-18");
var b = moment("2024-05-18");

var n = moment()
var t = moment().startOf('day');

let q =  b.diff(a, 'days');
let p =  b.diff(t, 'days');
let r =  t.diff(a, 'days');

let h = n.diff(a, 'hours');
let i = b.diff(a, 'hours');

let html = `**COUNTDOWN**     <progress style="height:10px;width:20%" value="`+h+`" max="`+i+`"></progress>`

if (r>0 && r<q) {
	html +=  `    **` +(h/i*100).toFixed(0)+`%** | `
	html += +p+` days remaining` 
} else if (r==0) {
	html += `    **` +(h/i*100).toFixed(0)+`%** | `+ p + ` days remaining`
} else if (r==q) {
	html += `   Ends today`
} else if (r>q) {
	html += `   Ended `+-p+` days ago`
}else {
	html += `   `+-r+` days remaining`

1 Like

Thanks Anwen, you’re a legend!!! Just what I was after, cheers.

Fine solution!
But how do I have to set the syntax, if I want to use the date from the current note in frontmatter/properties?

if my property fields are sdate (2024-03-13) and edate (2024-05-20)

when I set to:

var a = moment(dv.current().sdate).format("YYYY-MM-DD");
var b = moment(dv.current().edate).format("YYYY-MM-DD");

I get

Evaluation Error: TypeError: b.diff is not a function
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:10:12)
    at DataviewInlineApi.eval (plugin:dataview:18638:16)
    at evalInContext (plugin:dataview:18639:7)

console.log gives me for both of the dates:

I hate those date syntax stuff…

best regards

Again there may be more optimal, but I managed to make it work like this:

var a = moment(dv.current().sdate.toString().substring(0, 10))
var b = moment(dv.current().edate.toString().substring(0, 10))
1 Like

thank you very much!
This is completely sufficient for me. :grinning:

You could also try the variant of moment( dv.current().sdate.toISODate() ), if my memory serves me correctly.

1 Like

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