how to find sum of time duration in jasper ireport using grandtotal concept



I have created a report in jasper ireport which will find timedifference  and the sum of all timedifferences  for below table. am getting the output for timedifference. But facing problem when trying to find sum of that .I have used grandtotaling concept where i created a variable 'total' passed the time difference expression 'TimeDiff(updateddatetime,createdtime)'  in that  ,also created a textbox and called the variable 'total' in that . In the preview instead of sum ,iam getting only last value (timediff in this eg:4:17:00)  of the table.



     am expecting output as  total difference  =15:46:00 .

     Please help me

rajaniandroid2012's picture
Joined: Jan 21 2013 - 1:40am
Last seen: 6 years 8 months ago
please attach the JRXML. Also, to make sure that I understand you correctly - the last column should contain the total instead of the current difference?
mrcaffeine - 6 years 9 months ago
i have attached the file , i want two result in single output, 1. calulating timediff with createdtime and updateddatetime, which am getting the result. 2. total timedifference , which am not getting
rajaniandroid2012 - 6 years 9 months ago

2 Answers:


In the last table column you configured as text field expression $F{timediff(updateddateTime,CreatedTime)}, if I understand your requirement correctly, it should be $V{total} instead. This would aggregate the seconds, you'd need to modify the formatting so that you get the desired output. There might be a more elegant way, however this seems to work:

new SimpleDateFormat("HH:mm:ss").format(new Date((long)($V{total}*1000-TimeZone.getDefault().getOffset($V{total}))))

mrcaffeine's picture
Joined: Nov 10 2008 - 3:38am
Last seen: 2 years 4 months ago

But in the last Column it should calculate the time diff between createdDate and updatedDateTime,so I have used $F{timediff(updateddateTime,CreatedTime)}.but along with this I have to get the sum of all timediff and display in summary band, for which am unable to do.can you please guide me .

rajaniandroid2012 - 6 years 9 months ago

what is the output if you add "new SimpleDateFormat("HH:mm:ss").format(new Date((long)($V{total}*1000-TimeZone.getDefault().getOffset($V{total}))))" in the summary band?

mrcaffeine - 6 years 9 months ago

It is showing 00:00:00, also I have a doubt currently the data type of 'createdtime','updateddatetime','timediff' and 'total time diff' in 'string' format, but variable 'total' is in 'long' format... any thing to be changed in datatype.. the table i have provided is output of the report.along with the column 'timediff', i have to print sum of 'timediff' in summary band.please suggest

rajaniandroid2012 - 6 years 9 months ago

Hi All,

Any sollution of the above problem.

I am also facing the same issue.



gsingal's picture
Joined: Mar 4 2014 - 3:32am
Last seen: 5 years 7 months ago