Jump to content
We've recently updated our Privacy Statement, available here ×

Converting Seconds(Integer) to Hours:Minutes(Time)


Scorpio78

Recommended Posts

Hey everyone,

 

First off, I'm new to iReport, so please forgive me some nubish mistakes I might be making.

 

I'm running iReport 2.0.0

 

In a report I use a query which looks as follows:

Code:
  SELECT H.LocationNaam, H.ProjectCode, H.ProjectNaam, H.UursoortNaam, H.UserCode, H.UserANaam, H.UserVNaam, H.UserTV,
MAX(H.`Week`) AS `Week`,
SUM(H.Tijd) AS `Tijd Per Uursoort`
FROM urs_bjorn.hcn_hours H
GROUP BY H.LocationCode, H.ProjectCode, H.UursoortCode, H.UserCode
ORDER BY H.LocationNaam, H.ProjectNaam, H.UursoortNaam, H.UserANaam, H.UserVNaam;

 

Looking above in my query, you see I do a SUM on H.Tijd.

H.Tijd is an integer which represents seconds.

What I need to do, is convert these seconds to Hours:Minutes, having it as a Time format.

The amount of hours will supersede the 23 (think of a max of over a 1000 hours) and I want the mintues only to go up to 59.

 

Simply put, I want to see how much time was spent on a project.

The amount of time that could be spent on a project could be something like 1013 hours and 23 minutes, looking like this: 1013:23.

The value has to be a Timevalue and not a Stringvalue as it will be used to do calculations.

 

Can anyone tell me how to go about this?

 

Thanks in advance,

 

Björn

Post edited by: Scorpio78, at: 2007/07/25 12:48

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Use the scriptlet editor.

 

Create a function in your scriptlet that does the calculation of your field values. (Change seconds to minutes, minutes to hours, etc)

 

Call this function from a variable's expression

(a variable which you need to create, call it 'TotalTime' or something of the like)

 

The variable's expression should be something like:

 

$P{REPORT_SCRIPTLET}.calcTotalTime($F{hours}, $F{min}, {$F{seconds})

 

Display the variable in a textfield in your report.

 

P.S. Make sure you name the scriptlet class with this syntax:

 

public class (ReportName)Scriptlet extends...

 

Let me know if this works...Hope it helps

Link to comment
Share on other sites

  • 7 years later...

Put your seconds value in the chart as the measure, and then add the following property on the "show advanced properties" tab. 

property: yAxis.labels.formatter

value: function() { return parseInt(this.value/3600) + ":" + (parseInt((this.value % 3600) / 60)) + ":" + this.value % 60}

and if you want leading zeroes for minutes and seconds, you can try:

value: function() { return parseInt(this.value/3600) + ":" + ("0" + parseInt((this.value % 3600) / 60)).slice(-2) + ":" + ("0" + this.value % 60).slice(-2) }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...