Computing time difference in classical REXX

1510 views
Skip to first unread message

Arthur T.

unread,
Jan 14, 2014, 6:51:47 PM1/14/14
to
I'd like to compute the time difference between two time/date
stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.

Is there anything easier than computing the number of days
difference, converting to seconds, then adding the time difference,
and adjusting for partial days (e.g. if end-time is less than
start-time, subtract one day)?

I'd think this was a common operation, so someone has likely
already written and debugged code I could use. But if the answer is
in the newsgroup, my search hasn't found it.

(It probably wouldn't take me too long to write the code, but
then there's the problem in coming up with weird test examples to make
sure it's correct. I've decided that I'll probably ignore the
problems introduced by DST.)

In case it makes a difference, I'm using Regina on Windows.

--
Arthur T. - ar23hur "at" intergate "dot" com

LesK

unread,
Jan 14, 2014, 11:36:55 PM1/14/14
to
I have a routine to do that for THE, but it uses the ooRexx 'full'
option. You could use it as a base though, making appropriate adjustments.

Drop me a note if you'd like to see it.

--

Les (Change Arabic to Roman to email me)

Rony

unread,
Jan 15, 2014, 3:40:15 AM1/15/14
to
Try to locate "datergf" which does that and even more...

---rony


LesK

unread,
Jan 15, 2014, 4:31:10 AM1/15/14
to
Hmmm.... I have the 1996 OS/2 version :-)

Rony

unread,
Jan 15, 2014, 8:34:11 AM1/15/14
to
Hmm, I see. Tried to locate datergf via google in vain, hence I uploaded it to a new location for
downloading a few minutes ago.

"datergf.rex" is part of the "cronrgf" package, but can be used stand-alone as well:

http://wi.wu.ac.at/rgf/rexx/misc/cronrgf_with_datergf/CRONrgf-20111126.zip



Hint: an example from the commandline:

E:\\tmp>datergf "20120102 17:00:01", "-S", "20120101 17:00:00"
DATERGF - result: 1.00001157

Same example from within a Rexx program:

say datergf("20120102 17:00:01", "-S", "20120101 17:00:00")

output would be:

1.00001157

---

Another hint: if you just enter "datergf" on the command line you will get all options datergf
supports. However, in that particular case (invoking datergf without arguments) you will see ANSI
escape sequences (courtesy of "ScrColor.rex") for OS/2 caused colouring of the output which usually
is not available on Windows.

If you want to get rid of the ANSI escape sequences, then change the Rexx program "ScrColor.rex"
accordingly (just return empty strings instead of the ANSI escape sequences).

HTH,

---rony


Jeremy Nicoll - news posts

unread,
Jan 15, 2014, 3:39:22 PM1/15/14
to
Arthur T. <art...@munged.invalid> wrote:

> I'd like to compute the time difference between two time/date
>stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.
>
> Is there anything easier than computing the number of days
>difference, converting to seconds, then adding the time difference,
>and adjusting for partial days (e.g. if end-time is less than
>start-time, subtract one day)?

I'd probably do it slightly differently by expressing each date & time as a
number of whole & fractional days, essentially adding

(hh*3600 + mm*60 + ss)/86400

to each day's base date, to get values that are easily subtracted.

This doesn't take account of problems like clock changes twice per year.

--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "aaa" by "284".

Arthur T.

unread,
Jan 15, 2014, 7:11:39 PM1/15/14
to
In Message-ID:<mpro.mzgmpm...@wingsandbeaks.org.uk.invalid>,
Jeremy Nicoll - news posts <jn.nntp....@wingsandbeaks.org.uk>
wrote:

>Arthur T. <art...@munged.invalid> wrote:
>
>> I'd like to compute the time difference between two time/date
>>stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.
>>
>> Is there anything easier than computing the number of days
>>difference, converting to seconds, then adding the time difference,
>>and adjusting for partial days (e.g. if end-time is less than
>>start-time, subtract one day)?
>
>I'd probably do it slightly differently by expressing each date & time as a
>number of whole & fractional days, essentially adding
>
> (hh*3600 + mm*60 + ss)/86400
>
>to each day's base date, to get values that are easily subtracted.

I realized this was a probably better way when my search turned
up a REXX program to turn date & time into a Stardate. If dategrf
(via rony) doesn't do what I need, this is what I'll probably go with.

Arthur T.

unread,
Jan 15, 2014, 7:13:46 PM1/15/14
to
In Message-ID:<lb62o0$cr2$1...@speranza.aioe.org>,
Rony <rony.fl...@wu-wien.ac.at> wrote:

>Hmm, I see. Tried to locate datergf via google in vain, hence I uploaded it to a new location for
>downloading a few minutes ago.
>
>"datergf.rex" is part of the "cronrgf" package, but can be used stand-alone as well:

Thank you. Not only do you find me a tool, but you re-search for
it, and put it where I can find it. Then you give me some examples.
It looks like the tool does so much that there might be a bit of
learning curve. But, complex tools are often worth that investment of
time.

Again, thank you.

xad...@gmail.com

unread,
Jan 15, 2014, 8:03:34 PM1/15/14
to
Although you already have a very nice solution, if you want to do it from scratch, you may take as reference the algorithms in the book:
- Practical Astronomy with your Calculator ( http://www.amazon.com/Practical-Astronomy-Calculator-Peter-Duffett-Smith/dp/0521356997 )
There you have everything that gives you the basis to develop rexx routines to make all types of calculations with time stamps.

LesK

unread,
Jan 16, 2014, 12:37:32 AM1/16/14
to
On 1/15/2014 3:39 PM, Jeremy Nicoll - news posts wrote:
> Arthur T. <art...@munged.invalid> wrote:
>
>> I'd like to compute the time difference between two time/date
>> stamps. The inputs will be in the format of yyyymmdd hh:mm:ss.
>>
>> Is there anything easier than computing the number of days
>> difference, converting to seconds, then adding the time difference,
>> and adjusting for partial days (e.g. if end-time is less than
>> start-time, subtract one day)?
>
> I'd probably do it slightly differently by expressing each date & time as a
> number of whole & fractional days, essentially adding
>
> (hh*3600 + mm*60 + ss)/86400
>
> to each day's base date, to get values that are easily subtracted.
>
> This doesn't take account of problems like clock changes twice per year.
>
That's the approach I took when comparing the date/time of a file in a
zip archive with that of the file on disk. But I used the ooRexx 'Full'
option. which returns the number of microseconds since 00:00:00.000000
on 1 Jan 0001. That feature makes it fairly simple:

Numeric Digits 18 -- needed To add the timestamps
filestamp = Date('f', dt,'S','','-') + Time('f',tm, 'N')
zipstamp = Date('f', zdt,'S','','-') + Time('f',ztm, 'N')
timediff=(zipstamp-filestamp)/1000000

From there, it's straightforward to deal with DST and convert to
convenient display units.

Rony

unread,
Jan 16, 2014, 2:50:30 PM1/16/14
to
You are very welcome, hopefully it serves your purposes.

Ad functionality: I just pointed out that there is more in there and you probably have found the
documentation at the top of the code of datergf.rex. The options are somewhat mnemonic like "WB", is
the acronym for "Week Begin" and the like.

---rony


Message has been deleted

StuartKuz

unread,
Feb 5, 2020, 2:44:33 PM2/5/20
to
If the difference is between points in your code, time(E) is cool.
-Stuart
Reply all
Reply to author
Forward
0 new messages