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!

TIME CALCULATION 3

Status
Not open for further replies.

sqlpro

Programmer
Joined
Dec 30, 2003
Messages
297
Location
NZ
Hi friends
is there any way i can calculate total duration in the
following format.
D:HH:MM:SS

i have a table with a column that stores seconds i need to
calculate total duration by summing seconds column in above
format.How can i do that?
Thanks for your Idea .
 
You can get the total hours, minutes and seconds from your seconds field as follows:
Code:
lnHours = lnSeconds/3600
lnRemainder = mod(lnSeconds,3600)
lnMinutes = lnRemainder/60
lnSeconds = mod(lnRemainder,60)
Then you can glue them together into a single field:
Code:
lcTime = padl(lnHours,2,"0")+":"+padl(lnMinutes,2,"0")+":"+padl(lnSeconds,2,"0")


-BP (Barbara Peisch)
 
cool Barbara Peisch
that works greatly what if my total duration over a day .
how can chnage it to D:HH:MM:SS
thank you once again
 
A day is just 24 hours, so you just need to pull that out first:
Code:
lnDays = lnSeconds/86400  && 86400 = 60 seconds * 60 minutues * 24 hours
lnRemainder = mod(lnSeconds,86400)
lnHours = lnRemainder/3600  && 3600 = 60 seconds * 60 minutes
lnRemainder = mod(lnRemainder,3600)
lnMinutes = lnRemainder/60
lnSeconds = mod(lnRemainder,60)


-BP (Barbara Peisch)
 
Take the code below and cut-n-paste it into a prg file and run it from within VFP...

Code:
*!* First two lines are an example of it's use
?GetDuration(76858342)
?GetDuration(458923)

FUNCTION GetDuration(tcSeconds)
	LOCAL lcReturn, lnLeftOverSeconds, lnDays, lnHours, lnMinutes

	lnLeftOverSeconds = tcSeconds

	lnDays = GetDaysFromSecs(lnLeftOverSeconds)
	lnLeftOverSeconds = lnLeftOverSeconds - (lnDays * 86400)
	lnHours = GetHoursFromSecs(lnLeftOverSeconds)
	lnLeftOverSeconds = lnLeftOverSeconds - (lnHours * 3600)
	lnMinutes = GetMinutesFromSecs(lnLeftOverSeconds)
	lnLeftOverSeconds = lnLeftOverSeconds - (lnMinutes * 60)

	RETURN ALLTRIM(STR(lnDays)) + ":" + PADL(ALLTRIM(STR(lnHours)),2,"0") + ":" + PADL(ALLTRIM(STR(lnMinutes)),2,"0") + ":" + PADL(ALLTRIM(STR(lnLeftOverSeconds)),2,"0")
ENDFUNC

FUNCTION GetDaysFromSecs(tcSeconds)
	LOCAL lnReturn
	lnReturn = INT(tcSeconds/86400)
	RETURN lnReturn
ENDFUNC

FUNCTION GetHoursFromSecs(tcSeconds)
	LOCAL lnReturn
	lnReturn = INT(tcSeconds/3600)
	RETURN lnReturn
ENDFUNC

FUNCTION GetMinutesFromSecs(tcSeconds)
	LOCAL lnReturn
	lnReturn = INT(tcSeconds/60)
	RETURN lnReturn
ENDFUNC

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Thank you so much guys I'll try your solutions.
you guys are very fast :-)
cheers
Rajani
 
i just implemented your solution.
and its working so beautifully :-)
Thank you so much for your valuable time.
cheers
Rajani
 
SlightHaze.. you get a star from me.. excellent work. *thumbsup*

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top