Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Help with JS Function
DreamCoder
Hello Everyone,
I have a field in my report called "duration" where currently its end_time - start_time which usually gives me a decimal as the result. Say, 1.24115.
in coldfusion I have this handy dandy function that will figure a duration into this format: 00:00:00 where mask is hh:mm:ss.
Heres an example of how I have it written in coldfusion:
function secondToMinute(duration){
if(NOT isNumeric(duration)){
duration = 0;
}
h = int(duration/3600);
m = int(duration/60) MOD 60;
s = duration MOD 60;
return(numberFormat(h,'00') & ":" & numberFormat(m,'00') & ":" & numberFormat(s,'00'));
}
Any ideas of how I could write something like this in birt? And even better, where I could put it to use it?
Thanks in advance!
Amanda
Find more posts tagged with
Comments
mwilliams
Hi Amanda,
So, the decimal value is in your dataSet? What does it represent? Minutes? Seconds? You want to display it as a time field of format hh:mm:ss? Let me know.
DreamCoder
Hi! Yes the decimal value is in my dataset. It represents minutes, but it could actually represent seconds, since thats what the data is before I compute it. So for simplicity sake, lets say my "duration" field is in seconds.
duration = 5110 seconds
hour = duration/3600 = 1
minutes = (duration/60) MOD 60 = 25
seconds = duration MOD 60 = 10
So what I would like to show for my "Duration" field is 01:25:10.
Does that make sense? Thanks for your help!
mwilliams
Amanda,
You should be able to create a computed column of type DateTime with the expression:
new Date(0,0,0,0,0,row["duration"]);
Then, when you put that data field in the report, select the data element, go to the property editor section called "Format DateTime", choose custom from the format as drop down, then enter the following as the code:
HH:mm:ss
This should get you you elapsed time displayed how you're wanting it so long as you don't go over 24 hours.
DreamCoder
Works perfectly Michael. You are da man.
Many Thanks,
Amanda
mwilliams
Amanda,
No problem. Glad to help!
DreamCoder
got any ideas for how to handle time that goes above 24 hours?
Thanks!
Amanda
mwilliams
Amanda,
Would the output format of dd:hh:mm:ss work for you? Or what output would you be looking for?
DreamCoder
yeah that would work, currently with our reports it just shows up as hh:mm:ss - as in 49:22:36 - for billing purposes. It would work just as well if we did 02:01:22:36 or even 2d 02:22:36.
Thanks,
Amanda
mwilliams
Amanda,
You could do this in your computed column:
days = Math.floor(row["Seconds"]/86400);
secs = row["Seconds"]%86400;
new Date(0,0,days,0,0,secs);
Then, in your format code, do:
dd:HH:mm:ss
This should show you days up until you hit the limit in days of a month in the date element. You could obviously figure this as a string computed column and display it however you wanted, i.e. 2d 01:25:30 or 2 days, 1 hour, 25 minutes, and 30 seconds, etc.
Yohanan
Hi,<br />
<br />
I have the same issue but I need to use this pattern : "hh:mm:ss".<br />
<br />
My value (a Time data type) is 51 hours but BIRT print 03 hours.<br />
<br />
I guess because it can't go above 24 hours.<br />
<br />
is there a solution with BIRT built-in format options or is it mandatory to build your own String by hand.<br />
<br />
Thansk for any intel.<br />
<br />
Jean.<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="55497" data-time="1255457881" data-date="13 October 2009 - 11:18 AM"><p>
Amanda,<br />
<br />
<br />
You could do this in your computed column:<br />
<br />
<br />
days = Math.floor(row["Seconds"]/86400);<br />
<br />
secs = row["Seconds"]%86400;<br />
<br />
new Date(0,0,days,0,0,secs);<br />
<br />
<br />
Then, in your format code, do:<br />
<br />
<br />
dd:HH:mm:ss<br />
<br />
<br />
This should show you days up until you hit the limit in days of a month in the date element. You could obviously figure this as a string computed column and display it however you wanted, i.e. 2d 01:25:30 or 2 days, 1 hour, 25 minutes, and 30 seconds, etc.<br /></p></blockquote>