Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Elapsed time calculation has a bug in it? What is wrong?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00612404
Message ID:
00612434
Views:
24
Some Q&D stuff:

edate = {^2002\01\29 09:50:00}
ldate = {^2002-01-29,14:20:00}
datediff = ldate-edate
? PADL(int(datediff/3600),2,'0')+":"+PADL(INT((mod(datediff,3600)/3600)*60),2,'0')+":" + PADL(mod(datediff,60),2,'0')


yields:
04:30:00
but you can format it anyway you wish.
JLK




>Here's is my calculation for elapsed time. I subtract current time from start time to get elapsed time and show it as HH:MM in a listbox.
>
>Hours and minutes are off if
>Start Time is 09:50:00 and Current Time is 14:20:00. HH:MM is wrong.
>But if
>Start Time is 10:10:00 and Current Time is 14:20:00, HH:MM is right.
>
>Following is my code. What am I doing wrong? I am missing something. Thanks for your assistance. I am starting to spin my wheels on the back-half of the calculation. Thanks again.
>
>
>SELECT hospital
>SCAN
>* Calculate elapsed time
>	SET DECIMALS TO 0
>	secs1 = VAL(SUBSTR(TTOC(hospital.newdate),18,2))
>	mins1 = VAL(SUBSTR(TTOC(hospital.newdate),15,2))*60
>	hrs1 = VAL(SUBSTR(TTOC(hospital.newdate),12,2))*3600
>	secs2 = VAL(SUBSTR(TTOC(DATETIME()),18,2))
>	mins2 = VAL(SUBSTR(TTOC(DATETIME()),15,2))*60
>	hrs2 = VAL(SUBSTR(TTOC(DATETIME()-1),12,2))*3600
>	elapsed = (hrs2+mins2+secs2) - (hrs1+mins1+secs1)
>	hrs3 = elapsed/3600
>	mins3 = (elapsed - (INT(hrs3)*3600))/60
>	elapsed2 = PADL(ALLT(STR(hrs3-1)),2,"0")+":"+PADL(ALLT(STR(mins3)),2,"0")
>	IF (hrs3 > 1 OR mins3 > 20) AND ALLT(hospital.newstatus) <> "OPEN"
>		THISFORM.Image1.Visible = .T.
>	ELSE
>		THISFORM.Image1.Visible = .F.
>	ENDIF
>	REPLACE hospital.elapstime WITH ALLT(elapsed2)
>ENDSCAN
>
Nebraska Dept of Revenue
Previous
Reply
Map
View

Click here to load this message in the networking platform