Tinderbox Forum

How to do date/time arithmetic?

I’m trying to set up a schedule in the form of a list of notes that automatically adjust the start and end times of all notes if I change the start time of the first or change the duration

My idea was to chain them together with a rule:


And to set the $EndDate of each with a second part of the rule:

$EndDate=$StartDate+$Duration minutes

where $Duration is a user attribute of number type

This doesn’t work, however, but I can’t see why not.

Breaking it down, I find that on its own,

$EndDate=$StartDate+10 minutes

gives the expected result, but replacing the “10” with “$Duration” fails, even though $Duration is a number variable

Can anyone help me figure this out?

You might want to use the interval data type for $Duration, rather than numeric type. Your model works for me if I use interval.

Also, be careful not to use the first rule ($StartDate=$EndDate(prevSibling)) with the first note in a container, because it will always give the result of none, since there is no “previous sibling” for the first note.

1 Like

I concur with @PaulWalters that the best approach is an interval as it is specifically designed for (intervals of) time. but, if you don’t like/understand those, can you use a Number attribute here? Yes. Let’s investigate…

$EndDate=$StartDate+10 minutes

is better written as

$EndDate=$StartDate+"10 minutes";

But even better is:

$EndDate=date($StartDate +"10 minutes");

Now if Number-type attribute $Duration has a value of 10 this achieves the same as above)

$EndDate=date($StartDate +($Duration +" minutes"));

The extra parentheses are to ensure Tinderbox combines $Duration with the literal string “minutes” which can only reconcile to a string which then works inside date() for interval addition/subtraction.

(Tested in v7.1.0)

Paul/Mark, many thanks. I must have missed the introduction of the Interval attribute type – a lot of my Tbx knowledge was gleaned a few versions back now – it’s clearly the right solution here. A quick change of attribute type and it all works perfectly, as I’d originally intended.

1 Like

Could someone kindly explain how to set up $MyInterval in order to have it show the interval between $StartDate and $EndDate.

Unfortunately, all the links provided about did not offer a solution – at least for me. Is there an Eastgate-documention for this feature?

interval() returns, i.e. results in, Interval-type data. Thus:


You might want to also read this.

I’ve just added a bit of extra content to aTbRef’s note on the interval(date1,date2) function, linked to above, in order to try and clarify things a bit more.

perfect @mwra! Thank you!

1 Like