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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Formatting 1

Status
Not open for further replies.

kermitforney

Technical User
Mar 15, 2005
374
US
I need to be able to format the result of a time calculation.

Target TimeSpent Time Diff (in minutes)
200 75 125

I would like to display the TimeDiff as a time, so it is calculated as follows: 125/1440 formatted as a time = 02:05

I would like to format the result as 2hrs 5mins, how is this possible? I have seen dome formatting via control source, but have no experience myself.

Any help is greatly appreciated!!

TGIF :eek:D
 
=Format(([Target]-[TimeSpent])/1440, "h""hrs"" nn""mins""")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, to the rescuuuuuue . . again!!!

How did you become so dang knowledgeable PHV?? Now the only remaining question is, "How can resources be managed dynamically when using Database Mirroring in SQL Server 2008"?

Any insight PHV?? :eek:D TGIF!!!
 
Damn, I spoke too soon. Is there anyway to wrap the format in an If, Then or vice-versa??

Code:
=IIf(IsNull(Sum([lngTargetTime])/60),0,Sum([lngTargetTime])/60)
[\code]
 
You may try the Nz function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Couldn't get the syntazx to work correctly, so I tried the If/Then conditional again.

Got it!!
Code:
=Format(IIf(IsNull(Sum([lngTargetTime])/1440),0,Sum([lngTargetTime])/1440),"h""hr"" nn""min""")
 
There is one problem that has snuck it's little head into my solution!!

If the total is above 24hours, then the total resets.

Ex. If the result is 25:16 or 25hr 16mins, then what is displayed shows 1:16 or 1hr 16mins.

Anyway around this?
 
=IIf(IsNull(Sum([lngTargetTime])),"",(Sum([lngTargetTime])\60) & "hrs " & (Sum([lngTargetTime]) Mod 60) & "mns")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top