summing times
Hi,
I want to sum a list of job hours.
At the moment its summing the figures as if they are decimals.
ie: In the detail I have a DBText showing the hour times:
2:00, 2:22, 3:54, 4:23
In the group footer i have a DBCalc summing them.
I want to sum them taking into account 60 minutes per hour. Its treating
it as 100 minutes per hour.
Should sum to 12:39
Its currently summing to 11.99
How do I convert it to time format?
I have tried the StrToTIme operator but Im not sure how to use it.
Thanks
Red
I want to sum a list of job hours.
At the moment its summing the figures as if they are decimals.
ie: In the detail I have a DBText showing the hour times:
2:00, 2:22, 3:54, 4:23
In the group footer i have a DBCalc summing them.
I want to sum them taking into account 60 minutes per hour. Its treating
it as 100 minutes per hour.
Should sum to 12:39
Its currently summing to 11.99
How do I convert it to time format?
I have tried the StrToTIme operator but Im not sure how to use it.
Thanks
Red
This discussion has been closed.
Comments
I would suggest using a TppVariable to calculate the total minutes in a time
field. I believe the DBCalc component will be using the integer
representation of the datetime field to get the value and this is not in
minutes.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Ive tried that but how do I convert the data to hh:mm?
I have variable6 in the detail. It takes the hour value (double) from
the db.
Then variable7 in the group footer has the calc
Value := Variable6.value + Value;
Thsi sums the values. But its not according to hh:mm.
What do I need to add to the code?
Thanks
Red
Is the data type of the variable set to Time (dtTime), and your display
format set to hh:nn ? Try setting this up and see if there is a difference.
If not, you will need to use the built in Delphi DateTime conversion
utilities to convert the variant values in to TTime values.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
But i dont know how to incorporate them in the code.
I dont have a help module to show me.
thanks
Red
If you have your TppVariable's DataType set to dtTime, you can add or
subtract integer values from the initial value using the Delphi standard
TDateTime method. For instance whole numbers represent one day (24 hours),
and any fraction of a whole number represents the hours and minutes of that
day. So imagine the current time is 10:00AM.... if you add 0.25 (6 hours)
you should get 4:00PM. In Delphi it looks like the following...
procedure TForm1.ppVariable1Calc(Sender: TObject; var Value: Variant);
begin
Value := Now + 0.25;
end;
I tested this and it gave me the correct answer.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Im sorry but this isnt what Im looking to do.
My DB has man-hour values entered like so:
1.20, 1.45, 1.59.
These are one hour and twenty mins, one hour and forty five, etc.
Not 1.2 hours (=one hour and twelve)
So if I have the three values above, I need to sum them to get 5.04. five
hours and four minutes.
But my most important question is: How do i set a variable to type dtTime?
- ie WHERE does "dtTime" go in my code?
My code currently says:
"procedure Variable7OnCalc(var Value: Variant);
begin
Value := Variable6.value + Value;
end;"
Your code below doesnt mention dtTime.
Sorry to drag this out, but I just dont know how these operators work.
Thanks
Red
Unfortunately ReportBuilder only supports the time formatting that Delphi
provides. If you want to format a time value as you described below, you
will need to do so manually in your own separate method.
You can set the DataType of a TppVariable either at design time in the
Delphi Object inspector, or in the designer widow with the combo box in the
top left corner of the designer, or at run time using the
TppVariable.DataType property.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com