View previous topic :: View next topic |
Author |
Message |
psridhar Beginner
Joined: 16 May 2004 Posts: 68 Topics: 26
|
Posted: Fri Feb 17, 2006 8:37 am Post subject: Manipulating time in REXX |
|
|
Hi
I have two times with me (ex: 21:45 and 22:05). Is there a way to find its difference in REXX and display it. The result for the above example should be 00:20. Simillarly, a way for adding two times like 21:45 + 00:20 = 22:05 etc...
Thanks in advance
Sridhar P |
|
Back to top |
|
 |
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Fri Feb 17, 2006 9:52 am Post subject: |
|
|
Code: |
/* REXX Program CalTime */
parse arg time1 operator time2
parse var time1 hh1 ':' mm1 ':' .
parse var time2 hh2 ':' mm2 ':' .
If operator = '+' then time = (hh2 * 60 + mm2) + (hh1 * 60 + mm1)
Else time = abs((hh2 * 60 + mm2) - (hh1 * 60 + mm1))
say right(time % 60,2,'0')':'right(time // 60,2,0)
|
CalTime 21:45 - 22:05 Returns 00:20
CalTime 21:45 + 00:20 Returns 22:05 |
|
Back to top |
|
 |
psridhar Beginner
Joined: 16 May 2004 Posts: 68 Topics: 26
|
Posted: Fri Feb 17, 2006 10:17 am Post subject: |
|
|
Hi
Thank you for such a simple, wise idea.
Great........
Thanks again
Sridhar P |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Fri Feb 17, 2006 11:09 am Post subject: |
|
|
danm,
you should include the checking of 24 hours in case of summing minutes.
ex: 23:59
add 10 minutes.
should return 00.09 instead of 24:09
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|