Hi,
I have 2 fields in the database, TimeIn and TimeOut, I need to display the difference between both on the Grid, how can I do that and in which Event should be set?
Thank you
Hi,
I have 2 fields in the database, TimeIn and TimeOut, I need to display the difference between both on the Grid, how can I do that and in which Event should be set?
Thank you
Event onRecord:
$time_in_sec = strtotime({TimeIn});
$time_out_sec = strtotime({TimeOut});
// next day?
if ($time_out_sec < $time_in_sec)
{
// add one day (86.400 seconds)
$time_out_sec += 86400;
}
$diff_min = (($time_out_sec - $time_in_sec) / 60);
{your_difference_field} = $diff_min;
HTH.
[QUOTE=RHS;17258]Event onRecord:
$time_in_sec = strtotime({TimeIn});
$time_out_sec = strtotime({TimeOut});
// next day?
if ($time_out_sec < $time_in_sec)
{
// add one day (86.400 seconds)
$time_out_sec += 86400;
}
$diff_min = (($time_out_sec - $time_in_sec) / 60);
{your_difference_field} = $diff_min;
HTH.[/QUOTE]
Hi, Thank you, I am still having big difference:
[TABLE=“class: scGridTabela, width: 100%, align: center”]
[TR=“class: scGridLabel”]
[TD=“class: scGridLabelFont, align: center”]Time In
11:00:00
[/TD]
[TD=“class: scGridLabelFont, align: center”]Time Out
12:25:00
[/TD]
[TD=“class: scGridLabelFont, align: center”]Time Consumed
85:00:00
[/TD]
[/TR]
[/TABLE]
With your formula, I am getting 85:00:00 while it should be 01:25:00
Can you help please?
Thanks
The result is correct, the difference is 85 minutes… (60+25).
$diff_min = (($time_out_sec - $time_in_sec) / 60);
So you need to do a bit of work to get the notation as you want it…
Puh …
$h = floor($diff_min / 60);
$m = ($diff_min % 60);
$s = 0;
$diff_time = sprintf("%02d:%02d:%02d", $h, $m, $s);
Am I a bit too hard Reinhard?
Puh = … happiness had again …
[QUOTE=RHS;17277]Puh …
$h = floor($diff_min / 60);
$m = ($diff_min % 60);
$s = 0;
$diff_time = sprintf("%02d:%02d:%02d", $h, $m, $s);
[/QUOTE]
RHS, you’re super… many thanks