BBS: Inland Empire Archive Date: 06-01-92 (19:13) Number: 148 From: JEAN CREPEAU Refer#: NONE To: KEITH WATKINS Recvd: NO Subj: Elapsed Time Conf: (2) Quik_Bas
In a message to ALL, KEITH WATKINS wrote:
KW=> I am trying to write a routine that will give me the elapsed time from
the system clock. What I have works fine if you don't change hours,
but if the hour changes, my routine could report that a user has been
on for an hour and fifty eight minutes when in fact he has been on for
five minutes. Can anyone help me with this? Thanks! -Keith
Use the following function that gives you the difference between
two times.
DEFINT A-Z
FUNCTION Zero$(x,y)
Zero$=RIGHT$(STRING$(y,48)+LTRIM$(STR$(x)),y)
END FUNCTION
FUNCTION DiffTime$(T1$,T2$)
h=VAL(t2$)-VAL(t1$)
m=VAL(MID$(t2$,4,2))-VAL(MID$(t1$,4,2))
s=VAL(MID$(t2$,7,2))-VAL(MID$(t1$,7,2))
IF s<0 THEN s=s+60:m=m-1
IF m<0 THEN m=m+60:h=h-1
IF h<0 THEN h=h+24
DiffTime$=Zero$(h,2)+":"+Zero$(m,2)+":"+Zero$(s,2)
END FUNCTION
If you want co calculate the difference between two Time$, you just
have to do DT$=DiffTime$(InitTime$,Time$). The time format is hh:mm:ss.
Jean
---
* Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET