Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A Time Elapsed function: Answered my own question.
Message
 
To
16/07/1997 13:35:57
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Miscellaneous
Thread ID:
00040258
Message ID:
00040288
Views:
32
>>Well, since I was in a rush, I did in fact reinvent the wheel. I'm posting it here just in case anyone has need of it. The following function will accept two time strings (attained by using the TIME() fucntion) and return the hours, minutes, and seconds between the two times. It will not return days, however, since I had no use for it. So, if the difference between the two times is greater than 24 hours the result will be incorrect.
>>
>>********************************************************************
>>Procedure TimeElapsed &&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>>********************************************************************
>>Parameter pTimeStart,pTimeEnd
>>PRIVATE xBegHour,xBegMin,xBegSec,;
>> xEndHour,xEndMin,xEndSec,;
>> xHour,xMin,xSec,;
>> xElapsed,xError
>>
>>xError = "BAD TIME DATA"
>>
>>IF LEN(pTimeStart)<>8 or LEN(pTimeEnd)<>8 or ;
>> SUBSTR(pTimeStart,3,1)<>":" or SUBSTR(pTimeStart,6,1)<>":"
>> Return xError
>>ENDIF
>>
>>xBegHour = VAL(SUBSTR(pTimeStart,1,2))
>>xBegMin = VAL(SUBSTR(pTimeStart,4,2))
>>xBegSec = VAL(SUBSTR(pTimeStart,7,2))
>>xEndHour = VAL(SUBSTR(pTimeEnd,1,2))
>>xEndMin = VAL(SUBSTR(pTimeEnd,4,2))
>>xEndSec = VAL(SUBSTR(pTimeEnd,7,2))
>>
>>if xBegHour > xEndHour
>> xHour = (24 - xBegHour)+xEndHour
>>else
>> xHour = xEndHour - xBegHour
>>endif
>>
>>if xBegMin > xEndMin
>> xMin = (60 - xBegMin)+xEndMin
>> xHour= xHour - 1
>>else
>> xMin = xEndMin - xBegMin
>>endif
>>
>>if xBegSec > xEndSec
>> xSec = (60 - xBegSec)+xEndSec
>> if xMin = 0
>> xMin = 59
>> xHour= xHour - 1
>> else
>> xMin = xMin - 1
>> endif
>>else
>> xSec = xEndSec - xBegSec
>>endif
>>
>>xElapsed = ALLTRIM(STR(xHour))+"h "+ALLTRIM(STR(xMin))+;
>> "m "+ALLTRIM(STR(xSec))+"s"
>>
>>Return xElapsed
>
>Have you ever heard about SECONDS() function? It does alwost all your job.

Doesn't that return the number of seconds since midnight? What good would that do? Ah, wait...if i get the beginning seconds since midnight and the ending seconds since midnight and subtracted them..DOH! Ok, well, though it was a complete waste of my time, I enjoyed it. :-P

Michael G. Emmons
memmons@nc.rr.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform