In MS Reporting Services 2008, I have a field that is a duration stored as seconds. Is there a slick way to get it into hh:mm:ss format in a group section of the report?
相关问题
- How to account for clock offsets in a distributed
- Java Instant.parse on Date java 8
- Linux get system time since power on
- Calculate sum time in Oracle
- Is Sleep() inaccurate?
相关文章
- SQL Server Reporting Services - Set default value
- Get POSIX epoch as system_clock::time_point
- Rails: always include the milliseconds with create
- Will getting the current date/time be thread-safe
- strtotime('today') returning incorrect tim
- Format std::time output
- What is the simplest way to find the difference be
- How to get the current UTC time in seconds
use a function like this:
If you need to work with times longer than 24 hours (Chris Latta's solution will wraparound in these cases), then there are a couple of solutions.
Simple Formula
If you want to just use a formula on the field such the following from this thread, (which also links back to this question)!
If you need to pad your value to 2 characters you can wrap a
RIGHT("0" & {X}, 2)
around each sub-section, where{x}
indicates one of the individual calculations in the above formula.Code Behind
Another approach, also suggested in this thread, is to use
TimeSpan.FromSeconds
(doc), and there is an implementation of that on this blog, using custom code behind in the report.I ended up using the custom code approach (as I had lots of fields sharing this), and combining it with something more like the first method as I didn't want days to start appearing I just wanted hours to count up bigger than 23.
I added some custom code to the report as follows which pads all values to at least 2 characters, and allows hours to hours count up > 23.
and then called this from each cell in questions as follows:
I hope this helps someone else!
I've used the idea of Xan recently and due to the fact the numbers of seconds I have are quite large - I ran out of integer type limit. Therefore I designed a different approach - maybe someobody will find it useful :)
I needed to create calculated fields for Hours, Minutes and Seconds - used following formulas:
Then I created an expression to display the seconds in HH:MM:SS (without days - did not needed that) format:
(Sum(Fields!LWTNumberOfHours.Value)+int((Sum(Fields!LWTNumberOfMinutes.Value) + int(Sum(Fields!LWTNumberOfSeconds.Value)/60))/60))
& ":" &
right("0" & (Sum(Fields!LWTNumberOfMinutes.Value) +
int(Sum(Fields!LWTNumberOfSeconds.Value)/60)) Mod 60, 2)
& ":" &
right("0" & Sum(Fields!LWTNumberOfSeconds.Value) Mod 60, 2)
In the above lines you can see that line (1) calculates number of hours, line (3) calculates number of minutes and line (5) calculates number of seconds. Of course you can notice that additional calculations are made to get the number of full minutes out of XXNumberOfSeconds and same applies to Minutes/Hours. This could be also done in the calculated fields already (and maybe it would even be more right to do so :) ) - however I preferred to use the above approach.
This way I was able to still format very large numbers of seconds that exceeds integer typesize.
Use expression below, replace bold with your field containing the seconds variable.
=DateAdd(DateInterval.Second, Sum(Fields!totalDuration.Value), CDate("1900-01-01 00:00:00"))
I always apply formating in the textbox properties-
H"h "m"m "s"s" will show as "2h 16m 5s"
If you just want to display it, convert in an expression for the Value of the textbox:
If you want to do calculations on it, convert the seconds to a DateTime in your dataset. Using SQL:
In Linq this would be something like:
Then you can just format it as a normal DateTime.