⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

time difference



Alfandi Nurulmukhlis
  • profile picture
  • Member

Posted 08 October 2013 - 07:31 AM

hi there...

how can i get time difference ?

for ex :

i have presence table,

field : id,name,time_come,time_home,duration

duration field is difference between time_home and time_come (time_home - time_come)

how can i get it? what function i must do in GC? or any suggest / any tutorial link for beginner?

thanks in adv


briggers
  • profile picture
  • Member

Posted 09 October 2013 - 09:59 AM

Hi,

 

You use callback_column to calculate the value for the duration column then in your callback function use any of the php methods for calculating an interval (depending on which version of php you are using). So something like this (check the php date/time object docs to be sure)

$c->columns('id','name','time_come','time_home','duration');

$c->callback_column('duration',array($this,'_callback_interval'));
.
.
.
.
.
.
public function _callback_interval($value, $row)
  {
    $datetime1 = new DateTime($row->time_come);
    $datetime2 = new DateTime($row->time_home);
    $interval = $datetime1->diff($datetime2);
    return $interval->format('H:i:s');
  }