Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comare two hours

Status
Not open for further replies.

breyt

IS-IT--Management
Dec 9, 2002
66
FR
HI
How I can compare two field containing Hours minute second
I want to substract one from the others and get the difference in hours minute second
Thanks
breyt
 
this hasn't been fully tested but it's worth a go

-* set up two times
-SET &TIME1 = '120000';
-SET &TIME2 = '063723';

-* convert each into seconds
-SET &SSS1 = EDIT(&TIME1,'$$$$99');
-SET &SSM1 = EDIT(&TIME1,'$$99');
-SET &SSH1 = EDIT(&TIME1,'99');
-SET &SS1 = &SSS1 + (&SSM1 * 60) + (&SSH1 * 3600);

-SET &SSS2 = EDIT(&TIME2,'$$$$99');
-SET &SSM2 = EDIT(&TIME2,'$$99');
-SET &SSH2 = EDIT(&TIME2,'99');
-SET &SS2 = &SSS2 + (&SSM2 * 60) + (&SSH2 * 3600);

-* calculate difference in seconds
-SET &DIFF = &SS1 - &SS2;

-* get number of hours and subtract that number of seconds
-* from the balance
-SET &DIFFH = INT(&DIFF/3600);
-SET &DIFF = &DIFF - (&DIFFH * 3600);

-* get minutes and subtract that number of seconds from
-* the balance
-SET &DIFFM = INT(&DIFF/60);
-SET &DIFF = &DIFF - (&DIFFM * 60);

-* seconds is what's left over
-SET &DIFFS = &DIFF;

-TYPE &DIFFH &DIFFM &DIFFS
-EXIT

-* This produces the following

-SET &TIME1 = '120000';
-SET &TIME2 = '063723';
-SET &SSS1 = EDIT(120000,'$$$$99');
-SET &SSM1 = EDIT(120000,'$$99');
-SET &SSH1 = EDIT(120000,'99');
-SET &SS1 = 00 + (00 * 60) + (12 * 3600);
-SET &SSS2 = EDIT(063723,'$$$$99');
-SET &SSM2 = EDIT(063723,'$$99');
-SET &SSH2 = EDIT(063723,'99');
-SET &SS2 = 23 + (37 * 60) + (06 * 3600);
-SET &DIFF = 43200 - 23843;
-SET &DIFFH = INT(19357/3600);
-SET &DIFF = 19357 - (5 * 3600);
-SET &DIFFM = INT(1357/60);
-SET &DIFF = 1357 - (22 * 60);
-SET &DIFFS = 37;
-TYPE 5 22 37
5 22 37
-EXIT
 
HI
Thanks a lot
But I dnont know why there ares not subroutines
Breyt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top