May 16, 2007 at 5:01 pm
Good afternoon everyone i was wondering if anyone out there has done this... I have 11285847 seconds and i would like to format these seconds to come out in this kind of format "N days : N Hours : N Minutes" ... please help.. thanks
Moe C
May 17, 2007 at 12:53 am
Try this. I'm sure there's a ton of ways to do it. Not feeling very clever right now.
declare
@Seconds int
Set
@Seconds = 11285847
declare
@Days int
declare @Hours int
declare @Minutes int
Set
@Days = @Seconds / 86400
set @Hours = (@Seconds % 86400) / 3600
set @Minutes = ((@Seconds % 86400) / 3600) / 60
set @Seconds = ((@Seconds % 86400) / 3600) % 60
select
ltrim(str(@Days)) + ' Days : ' + ltrim(str(@Hours)) + ' Hours : ' + ltrim(str(@Minutes)) + ' Minutes : ' + ltrim(str(@Seconds)) + ' Seconds'
May 17, 2007 at 3:16 am
That doesn't look right.
Try this
declare @Seconds int
declare @Date smalldatetime
Set
@Seconds = 11285847
declare
@Days int
select @Date = dateadd(ss, @Seconds, '01/01/1900')
select @Days = datediff(dd, '01/01/1900', @Date)
select ltrim(str(@Days)) + ' Days : ' + ltrim(str(datepart(hh, @Date))) +
' Hours : ' + ltrim(str(datepart(mi,@Date))) + ' Minutes : ' + ltrim(str(datepart
ss, @Date))) + ' Seconds'
Result
130 Days : 14 Hours : 57 Minutes : 0 Seconds
May 17, 2007 at 6:36 am
Ooooowwww.... why on Earth do you want to do this? Even if it's just a report, if someone needs to ananlyze the data using any form of aggragation, they're pretty much screwed into having to undo the formatting you're doing. This type of thing should really be done in "the application" if you have one. If it's for a file you need to send someone, they'll pretty much be in the same boat.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 17, 2007 at 11:03 am
Well i was hoping that i wouldnt need a SP and i can just do the formatting in the RDL... the customer wants to see something pretty and not 7200 seconds ...
Moe C
May 17, 2007 at 11:54 am
Oh, you wanted it for reporting services.
You can basically do the same thing using VB Script.
=Int((Fields!Seconds.Value / 86400)) & " Days : " &
Int(((Fields!Seconds.Value Mod 86400) / 3600)) & " Hours : " &
Int((((Fields!Seconds.Value Mod 86400) Mod 3600) / 60)) & " Minutes : " &
(((Fields!Seconds.Value Mod 86400) Mod 3600) Mod 60) & " Seconds "
May 17, 2007 at 2:01 pm
This is great Ray.. thanks for all your help...
Moe C
May 18, 2007 at 12:01 am
I'll be the first to agree with making the end result pretty... I'm just not sure why they don't do that at the presentation layer... or, maybe that's the problem? They don't have a "presentation layer"?
Just curious... that's all...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply