Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Problems displaying time interval in hh:mm format
ttessitore
I am attempting to compute a time duration between 2 fields. I created a data report item. The following expression in the data report item correctly computes the number of minutes in the interval:
(dataSetRow["offdutyeffectivetimestamp"].getTime()-dataSetRow["ondutyeffectivetimestamp"].getTime())/1000/60
I want to convert this into hh:mm format and display it into the data report item field. I put the following code into the onCreate event:
timeDiff=this.getValue();
Hours = Math.floor(timeDiff/60);
Minutes = timeDiff%60;
Minutes = String("0" + Minutes).slice(-2);
Time = Hours + ":" + Minutes;
this.Data = Time;
The Time variable is producing the correct results, but I can't get it to display in the field. I have tried this.Data, this.setDisplayValue, etc..., but nothing seems to work. Any help would be greatly appreciated.
Find more posts tagged with
Comments
johnw
reportContext.setGlobalVariable("currentTime", Time);
In your Data/Dynamic Data item, you would display it as:
reportContext.getGlobalVariable("currentTime");
There are a few other ways, but this should work.
ttessitore
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="85083" data-time="1320797746" data-date="08 November 2011 - 05:15 PM"><p>
reportContext.setGlobalVariable("currentTime", Time);<br />
<br />
In your Data/Dynamic Data item, you would display it as:<br />
reportContext.getGlobalVariable("currentTime");<br />
<br />
There are a few other ways, but this should work.<br /></p></blockquote>
<br />
I am a little confused. Where exactly would I put this code? My code exists in the onCreate section of my Data type report item. I have a variable called Time that has the interval in the format I want to display. I simply want Time to be displayed. When I use a dynamicText report item type, all I would have to do is:<br />
<br />
this.text = Time;<br />
<br />
I am trying to do the same thing in a Data report item type. I have tried:<br />
<br />
this.data = Time;<br />
this.setDisplayValue(Time);<br />
this.setValue(Time);<br />
<br />
Nothing seems to work. The reason I don not set this up as as dynamicText field is that I have aggregate on the numbers of minutes for a Total Number of minutes for a group. I don't think we can aggregate on a text field.
mwilliams
You might also run into type issues trying to change the value of an integer data element to a string. Why not just create 2 computed columns in your dataSet? One to figure the difference between the columns in minutes and one to show the string hh:mm representation? Then, in your table, you can display the string field, but aggregate on the integer difference field.
Or, you could simply use a text box to display the hh:mm format you want. As long as you have a computed column that figures the other value or a binding added just to your table, you'll be able to aggregate over this binding. Then, you'll only have to add a single field to your dataSet or table.
Maybe I'm missing something, let me know.