mondejars
Member
Hi there, first time posting on the forum, not a lot of php or SQL skills.
I have a timesheets list with the following elements:
User (User element).
Date (Date element).
Time in (time element, '{timesheets___time_in}', time type on db).
Time out (time element, '{timesheets___time_out}' time type on db).
Pause (dropdown, '{timesheets___pause}', time type).
Field types modification is locked in list settings.
I have been reading a lot about how to calculate durations on Fabrik and tried a lot of example codes (php, SQL), this code is returning the right values for me on a calc element:
The only problem I am having is when there is an overnight shift, it returns a negative value. I understand there has to be a condition to add a day like "IF '{timesheets___time_out}' < '{timesheets___time_in}' ELSE ..." so I have tried using DATEADD, but as I said before, I am not really skilful with SQL therefore no success.
Could you guys please point me in the right direction to keep investigating how to do this?
Thank you very much in advance.
PS. Fabrik is amazing
I have a timesheets list with the following elements:
User (User element).
Date (Date element).
Time in (time element, '{timesheets___time_in}', time type on db).
Time out (time element, '{timesheets___time_out}' time type on db).
Pause (dropdown, '{timesheets___pause}', time type).
Field types modification is locked in list settings.
I have been reading a lot about how to calculate durations on Fabrik and tried a lot of example codes (php, SQL), this code is returning the right values for me on a calc element:
Code:
$db = JFactory::getDbo();
$query = "SELECT SEC_TO_TIME(TIME_TO_SEC('{timesheets___time_out}')
- TIME_TO_SEC('{timesheets___time_in}')
- TIME_TO_SEC('{timesheets___pause}'))";
$db->setQuery($query);
$duration = $db->loadResult();
return $duration;
The only problem I am having is when there is an overnight shift, it returns a negative value. I understand there has to be a condition to add a day like "IF '{timesheets___time_out}' < '{timesheets___time_in}' ELSE ..." so I have tried using DATEADD, but as I said before, I am not really skilful with SQL therefore no success.
Could you guys please point me in the right direction to keep investigating how to do this?
Thank you very much in advance.
PS. Fabrik is amazing
Last edited: