Elapsed Time Example Involving Different Days
ID: Q115989
2.00 2.50 2.50a 2.50b 2.60 | 2.50 2.50a 2.50b 2.60 3.00| 2.50b 2.50c
MS-DOS | WINDOWS | MACINTOSH
The information in this article applies to:
- Microsoft Visual FoxPro for Windows, version 3.0
- Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6
- Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
- Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c
SUMMARY
The function shown below determines the number of seconds that have elapsed
between two different times. This function will take into account switching
to the next day.
MORE INFORMATION
PROCEDURE elaptime
PARAMETER m.startdate, m.enddate, m.starttime, m.endtime
* pass startdate, an 8-character starttime (HH:MM:SS), an enddate,
* and an 8-character endtime
* perform parameter type checking: return value of -1 indicates
* invalid parameter type
* Example of using the function elaptime:
* TempVariable=ElapTime({01/01/94},{01/02/94},"00:01:00",00:01:00")
IF TYPE('m.startdate') # "D" .OR. ;
TYPE('m.enddate') # "D" .OR. ;
(TYPE('m.starttime') # "C" .AND. LEN(m.starttime) # 8) .OR. ;
(TYPE('m.endtime') # "C" .AND. LEN(m.endtime) # 8)
RETURN -1
ENDIF
* if startdate > enddate, or same date and starttime > endtime,
* return 0
IF m.startdate > m.enddate .OR. (m.startdate = m.enddate .AND. ;
m.starttime > m.endtime)
RETURN 0
ENDIF
#DEFINE secsperday 86400
* determine whether the endtime is earlier or later than the
* starttime
IF m.endtime >= m.starttime
m.elapsecs = (m.enddate - m.startdate) * secsperday + ;
(time2secs(m.endtime) - time2secs(m.starttime))
ELSE
m.elapsdays = 0
IF m.enddate - m.startdate > 0
m.elapsdays = m.enddate - m.startdate - 1
ENDIF
m.elapsecs = (m.elapsdays * secsperday) + ;
(secsperday - time2secs(m.starttime)) + ;
time2secs(m.endtime)
ENDIF
RETURN m.elapsecs
FUNCTION time2secs
* passed a C8 HH:MM:SS string
* returns the number of seconds into the day this is
PARAMETER m.passedtime
m.retsecs = VAL(RIGHT(m.passedtime, 2)) + ;
60 * VAL(SUBSTR(m.passedtime, 4, 2)) + ;
3600 * VAL(LEFT(m.passedtime, 2))
RETURN m.retsecs
Additional reference words: VFoxWin 3.00 FoxWin FoxDos 2.60 calculate udf
KBCategory:
KBSubcategory: FxprgGeneral
Keywords : kbcode FxprgGeneral
Version : 2.00 2.50 2.50a 2.50b 2.60 | 2.5
Platform : MACINTOSH MS-DOS WINDOWS
|