Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i convert secs. into hours?

Status
Not open for further replies.

wilsondg

Vendor
Jun 30, 2007
5
US
can someone help me... how can i convert seconds into hour....

i.e: i have 1000 secs. how can i convert this into hours?

Help.....
 
I use:
FUNCTION SS2HHMMSS
LPARAMETERS p_nSeconds
LOCAL l_nHours, l_nMinutes, l_nSeconds
l_nHours = INT(p_nSeconds / 3600)
l_nMinutes = INT((p_nSeconds - 3600*l_nHours) / 60)
l_nSeconds = MOD(p_nSeconds, 60)
RETURN ALLTRIM(TRANSFORM(l_nHours, "9999"));
+ ":"+TRANSFORM(l_nMinutes, "@L 99");
+ ":"+TRANSFORM(l_nSeconds, "@L 99")

Rick
 

lnTotalSeconds = 1000

lnHours = INT(lnSeconds/3600)
lnMins = INT(MOD(lnSeconds,3600)/60)
lnSecs = MOD(lnSeconds,60)

** To put in HH:MM:SS format...
? TRANSFORM(lnHours, "@L 99") + ":" + ;
TRANSFORM(lnMins, "@L 99") + ":" + ;
TRANSFORM(lnSecs, "@L 99")


 
wilsondg
As you can see by Rick's code I made a mistake, it should read:
nHours = 10000/3600

Although to convert minutes from decimal to actual minutes Rick's function might be more help.
 
You guys are the best! tnx rick!

another thing.. i need to add up the results of your function, you know to get the total # of hours.

i was thinking to create another field named secs then ill save the secs (before the conversion) as a numeric value.. then compute it with your function to get the total # of hours:min:secs....

i dont mean to brag but is there a way to computer the results of your function... i.e. 1:30:20 + 2:15
:60 ?

:)

tnx



 
Wilsondg

The suggestion that Rick made "transforms" the result into characters, so with that in mind you cannot add character together.
But if you further modify Rick's function, you can achive the desired result (Just don't forgot to deal with the seconds adding to more then then 60 and the minutes adding to more then 60)
Code:
LOCAL lnHoursVal1,lnHoursVal2,lnMinsVal1,lnMinsVal2,lnSecVal1,lnSecVal2,lnTotalSeconds1,lnTotalSeconds2
STORE 0 to lnHoursVal1,lnHoursVal2,lnMinsVal1,lnMinsVal2,lnSecVal1,lnSecVal2,lnTotalSeconds1,lnTotalSeconds2
LOCAL lngTotalHours,lngTotalminutes,lngTotalSeconds,lngTotalTime
STORE 0 to lngTotalHours,lngTotalminutes,lngTotalSeconds,lngTotalTime

lnTotalSeconds1 = 1000
lnTotalSeconds2 = 6000
SET step on
lnHoursVal1 = INT(lnTotalSeconds1/3600)
lnMinsVal1  = INT(MOD(lnTotalSeconds1,3600)/60)
lnSecVal1  = MOD(lnTotalSeconds1,60)

lnHoursVal2 = INT(lnTotalSeconds2/3600)
lnMinsVal2  = INT(MOD(lnTotalSeconds2,3600)/60)
lnSecVal2  = MOD(lnTotalSeconds2,60)

IF lnSecVal1+lnSecVal2>60
	lngTotalSeconds = lnSecVal1+lnSecVal2-60
	lngTotalminutes = 1
ELSE
	lngTotalSeconds = lnSecVal1+lnSecVal2
ENDIF
IF lnMinsVal1+ lnMinsVal2 > 60
	lngTotalminutes = lngTotalminutes+((lnMinsVal1+lnMinsVal2)-60)
	lngTotalHours = 1
ELSE
	lngTotalminutes = lngTotalminutes+(lnMinsVal1+lnMinsVal2)
ENDIF
lngTotalHours = lngTotalHours+(lnHoursVal1+lnHoursVal2)

MESSAGEBOX(TRANSFORM(lngTotalHours, "@L 99") + ":" + ;
	TRANSFORM(lngTotalminutes, "@L 99") + ":" + ;
	TRANSFORM(lngTotalSeconds, "@L 99"))






 
Wilsondg

Of course that above function can be used as a custom method in a form by adding parameters (lnTotalSeconds1,lnTotalSeconds2)

Code:
DO thisform.hoursCalc(nTotalSeconds1,nTotalSeconds2)
And in the Function, the first line is :
Code:
LPARAMETERS lnTotalSeconds1,lnTotalSeconds2
Remove lines 5 and 6 and don't declare lnTotalSeconds1 and lnTotalSeconds2 as locals and don't set them as 0 in the function, do it before the function.




 
You guys r really the best! this site should be emulated by microsoft or this site should get paid big time by microsoft!....

Tnx rick and mgagnon.

1) How do i put vfp executables in the system tray... (i.e a form) ?

2) Guys, Is there a good resource for learning database network programming in vfp?


Tnx a lot guys!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top