calc field, sum column error?

tusa

Member
Hello.
I have a calc field whree I calculate hours.
I usw a select command:
Code:
SELECT TIME_FORMAT(SEC_TO_TIME(TIME_TO_SEC('{fab_timeregistrering___slut}') - TIME_TO_SEC('{fab_timeregistrering___start}')), '%H:%i')
It calculate the hours between 2 date/time field.
How can I calculate across 2 different dates?
If I do that right now I only get a - before and the wrong amount of hours.

brg Tue.
 
I'm confused. Why are you using a query? Those placeholders will get replaced by the values of those elements, they won't be table field names. So there's no point doing that in MySQL.

Using PHP, it would be something like ...

Code:
$slutDate = new DateTime('{fab_timeregistrering___slut}');
$startDate = new DateTime('{fab_timeregistrering___start}');
$dateDiff = $slutDate->diff($startDate);
$hours = ($dateDiff->format('%a') * 24) + $dateDiff->format('%h');
$minutes = $dateDiff->format('%i');
return $hours . ':' . $minutes;

-- hugh
 
Thank you for answer, that worked fine for me.
I also could use it to get firther with some of my other fields.
 
Have an issue with this.
I have made the calc field, and that seemes to work.

But if I sum this column in the list, it's not giving med the right answer.


Udklip timer.PNG
I have used the calculation method as desrcibed above.

How can I fix this?
 
Last edited:
A calc field is text, so your sum is "correct" ((int)'14:30' =14 etc)

But no idea at the moment how to handle this.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top