Testing date/time equality

Historically in Tinderbox, $DateA is equal to $DateB as long as they are the same calendar day regardless of the time component. Thus if $DateA is 1 Oct 2014 10:32 and $DateB is 1 Oct 2014 11:44 a test of $DateA==$DateB would return true. In the past, and when Tinderbox action code was much simpler this approach made sense, especially for those doing calendar/to-do type work.

However, given the above, do you test two Date-type (i.e. date-time based) attributes have exactly the same value, i.e. including the time portion of the value as well?

Having tripped over this just the other day, I’ll share the solution (and which I’ve added to relevant aTbRef pages), which is to use interval() and test for a zero length interval. The default value for a ‘non’ interval is the string “oo:00” (see here). So the test is `interval($DateA,$DateB)', which might be used in an if() test like so:

if(interval($DateA,$DateB)=="00:00")){...

Having manually transcribed >4k pairs of start/end dates I was keen to check for human error where I’d pasted one value into both attributes. The latter test above proved that indeed, I had done this a couple of times and a simple $DateA==$DateB test whilst more intuitive, would not have found those few errors.

I’ve updated the aTbRef pages on == and != operators (and a few other pages) to cover this date-matching scenario.

2 Likes