Hi there,

I have a date time field to input working hours and calculate total work hours.

Lets say the rule in office is:
Employee In 1: 07.00
Employee Out 1: 12.00
Employee In 2 : 13.00
Employee Out 2 : 17.00

It's mean that employee have 8 hours a day.

The question is, how can I calculate that employee is late in 2 ours if the field value like this:

filed Employee In 1: 08.00 <- late
field Employee Out 1: 12.00
field Employee In 2 : 13.00
field Employee Out 2 : 16.00 <- earlier out

is there any module date related or some one chould assist me.

Thanks before.

BR,

Comments

tinohuda created an issue.

saurabh.dhariwal’s picture

You can override views template file and add below code. The below code will find difference between two in-timings and two out-timings and calculates total worked hours. This is assuming there won't be exactly 2 in and 2 out.

$start = strtotime($row->field_field_time_in[0]['raw']['value']);
$end = strtotime($row->field_field_time_out[0]['raw']['value']);
$diff = $end - $start;
$secondstart = strtotime($row->field_field_second_time_in[0]['raw']['value']);
$secondend = strtotime($row->field_field_second_time_out[0]['raw']['value']);
$seconddiff = $secondend - $secondstart;
$diff = $diff+$seconddiff;
$hours = floor($diff /3600);     
$minutes1 = intval(($diff/60) % 60);
print $hours.'.'.$minutes1;

You can add any required calculations you require based on this.

Thanks!