Trouble with duration calculation

What I’m trying to do

I want to create a template for planning class hours. I use meta data to include the rhythm (like every week) and the start date of a course. With this information I wrote some inline DQLs to generate headers for each class hour. So I have something like:

“—

rhythm : 7 days
startdate: 2023-09-04
—”

KW =dateformat(this.startdate+ 0 * this.rhythm ,"W") - =dateformat(this.startdate+ 0 * this.rhythm ,"EEE, dd.MM.yyyy")

KW =dateformat(this.startdate+ 1 * this.rhythm ,"W") - =dateformat(this.startdate+ 1 * this.rhythm ,"EEE, dd.MM.yyyy")

To get something like

KW 36 - Mo., 04.09.2023

KW 37 - Mo., 11.09.2023

However I run into problems for some durations and the result is not as expected (e.g. shows a Wednesday when it should always be a Monday).

KW 40 - Mi., 04.10.2023

Things I have tried

I “debugged” it a little and found out that the code does something strange when it comes e.g. to “4 * 7 days”:

=(4 * this.rhythm ).days

turns into

30

I believe somehow it is recognized as a month and that would be 30 days, even though I want it to be 4 * 7 days = 28 days. I tried to write the rythms as hours and other formats but I can’t get this to work.

Does anyone have an idea how to solve this? Thank you very much!

As you’ve written it now, your rhythm variable holds the duration directly, and this could cause some issues related to months as you’ve experienced. I think you can solve this by changing it to a pure number, and then create the duration directly when you’re calculating the new dates.

`=dateformat(this.startdate+ dur(1 * this.rhythm + " days"), "W")`

I think this’ll circumvent the conversion to months.

Thank you very much, this seems to work!

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