Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Date arithmetic with time results (Read 13551 times)
Boris Gordon
Full Member
*
Offline



Posts: 8

Date arithmetic with time results
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) ?

Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Date arithmetic with time results
Reply #1 - 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,"*")


Back to top
 
 
WWW   IP Logged
Boris Gordon
Full Member
*
Offline



Posts: 8

Re: Date arithmetic with time results
Reply #2 - 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.

Back to top
 
 
  IP Logged
maurice
Full Member
*
Offline



Posts: 81
London, UK
Re: Date arithmetic with time results
Reply #3 - 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.

Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Date arithmetic with time results
Reply #4 - Sep 30th, 2008, 5:44am
 
IntStart=(format($MyDate,"s")
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
maurice
Full Member
*
Offline



Posts: 81
London, UK
Re: Date arithmetic with time results
Reply #5 - 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?
Back to top
 
« Last Edit: Sep 30th, 2008, 7:21am by maurice »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Date arithmetic with time results
Reply #6 - 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.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
maurice
Full Member
*
Offline



Posts: 81
London, UK
Re: Date arithmetic with time results
Reply #7 - Sep 30th, 2008, 4:10pm
 
Thanks Mark, I'll play around a bit more...
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print