Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Date arithmetic with time results
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1219506354

Message started by Boris Gordon on Aug 23rd, 2008, 11:45am

Title: Date arithmetic with time results
Post by Boris Gordon on Aug 23rd, 2008, 11:45am

The result of Number = $Date1 - $Date2 gives the number of days between Date1 and Date2.

What's the best way to get the result in hours or minutes as a difference in times (i.e. I want the difference in timestamps) ?


Title: Re: Date arithmetic with time results
Post by Mark Bernstein on Aug 23rd, 2008, 12:06pm

Offhand, you could coerce the dates to integers, and subtract the integers; this would give you the difference in seconds.

    MyInt1=$Date1; MyInt2=$Date2;Interval=$MyInt1-$MyInt2;

Or, you could use a simple shell script:

    runCommand("MyScript "+format($Date1,"*")+" "+format($Date2,"*")



Title: Re: Date arithmetic with time results
Post by Boris Gordon on Aug 23rd, 2008, 12:35pm

Solution 1 looks good but I am getting weird results.

e.g. MyInt1=$Created gives a value of 24 and a later date/time gives the same number.


Title: Re: Date arithmetic with time results
Post by maurice on Sep 30th, 2008, 5:18am

Same is happening to me, with Tb 4.5.2. I have two Date attributes, Start and Stop, and two Numerical attributes (IntStart=$Start;IntStop=$Stop)

The two dates show different times on the same day (30 September). The two numerical attributes are identical ie 30. They seem only to recognise whole days, not shorter intervals, so don't appear capable of calculating the difference between two times in seconds.


Title: Re: Date arithmetic with time results
Post by Mark Anderson on Sep 30th, 2008, 5:44am

IntStart=(format($MyDate,"s")

Title: Re: Date arithmetic with time results
Post by maurice on Sep 30th, 2008, 7:12am

Thanks - but I'm not sure I've got this right yet. When I put the result of the "format" function into a text string (or output it as a number), the result is 0.

ie what I now have is a Date attribute (Date1) and a seconds attribute (Secs1) and this Rule:

Secs1=(format($Date1,"s")

I must be overlooking something, but what?

Title: Re: Date arithmetic with time results
Post by Mark Anderson on Sep 30th, 2008, 7:43am

Yes, but if you pass a text string of numbers, for example "30" to a number attribute it should coerce that to a number.  So I'd avoid left-zero-padded numbers and text in your format strings.

What there isn't (feature request?) is a format that gives you the date in browser JavaScript style as a number of milliseconds since  X (for JS, X = GMT midnight 1/1/1970).

Exactly how you go about this rather depends on the sorts of durations your trying to capture. IOW, are we measuring a few minutes worth of seconds or decades worth. In the latter case you might want to look at a command line or shell script to do the heavy lift of calculation.

Title: Re: Date arithmetic with time results
Post by maurice on Sep 30th, 2008, 4:10pm

Thanks Mark, I'll play around a bit more...

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.