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:
00612422
Views:
32
He-he-he. You're so wrong. You will get negative elapsed time by this code :))
You need to switch datetime and newdate.

>You can simplify your calculations
	elapsed = hospital.newdate - Datetime()
>	hrs3 = Int(elapsed/3600)
>	mins3 = Int((elapsed - (hrs3*3600)/60)
>	elapsed2 = Transform( hrs3*100 + mins3, "@RL 99:99")
>
>>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
>>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform