I would like to, e.g., estimate the time elapsed between $EndDate and $StartDate and display that as the note’s SubTitle. I tried with the following Rule:
I believe this returns the difference in days. The calculation works on the day value, i.e. 25/11/2017 23:50 and 26/11/2017 01:00 are treated in the above context as a difference of 1 (day) although in fact only an hour and 10 minutes apart.
The more formal way of doing this is the days(date1,date2) method. I’d recommend taking a look at my listing of action codes, especially the ones related to Date (Date.etc…) and Interval (Interval.etc…) data types. As with days() there are also years(), months(), hours() and minutes() operators. Note that the Interval type is quite recent and in some cases replaces - or is a more practical alternative - to earlier Date based examples.
Note the first term in the rule. The construct if($EndDate!=0) returns an indeterminate result because $EndDate is a date-type attribute, the “zero state” is undefined. What you want to test for is “there is an end date”, that is “exists $EndDate is True”. Thus if($EndDate)
The rest of the rule uses the form of the interval operator that compares start and end dates.
Be aware, though, that the interval operator is dynamic – it updates itself continually. So if you used the rule I suggested, the $Subtitle would be continually updated (watch the seconds in the GIF):
This can be interesting**, but it might also be an ongoing computation drain, potentially, if you have a lot of this going on in a file. If that is the case, then the alternate approaches mentioned by @mwra might be more attractive.
** For example, we can watch time tick away as we neglect our chores and never reach the $EndDate
My understanding is that months() returns the number of whole months, i.e. an integer (always rounded down to give complete whole months), and this is what I see testing in the current (v7.3.0) app would confirm that. Therefore you don’t actually don’t need precision.
I can replicate the output you describe, which indicates that although months() returns a number it is in string form. thus is the month difference is 8 then:
$SomeNumber = months($StartDate,$EndDate)precision(0); then $SomeNumber is 0
But if we coerce the output to a number:
$SomeNumber = months($StartDate,$EndDate).toNumber.precision(0); then $SomeNumber is 8
I need to check with Eastgate but this leads me to suppose all the years(), months(), etc., family of operators output an integer in String a form and not a Number as I’d assumed (but not documented). I’ll check and update documentation as/if needed.