Calculate date
- Single Page
Posted 20 February 2012 - 20:57 PM
Posted 20 February 2012 - 21:34 PM
function duration_calc($start, $end){//The format must be Y-m-d , m-d-Y, Y/m/d
$days = (strtotime($end) - strtotime($start)) / (60 * 60 * 24);
return $days;
}
I also have a helper that I've created ( it is old but it works ) that extend the date_helper of codeigniter: [attachment=52:date_helper.php]
It is better thought to ask this kind of questions at the Codeigniter forum at: http://codeigniter.com/forums/ because perhaps your questions will not be answered here if there is not for the library of grocery CRUD.
Kindest Regards
Johnny
Posted 20 February 2012 - 23:38 PM
Posted 21 February 2012 - 02:52 AM
public function layout(){
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('template');
$this->db->order_by('cliente','asc');
$crud->set_relation('cliente','cliente','nome');
$crud->set_relation('responsavel','responsavel','nome');
$crud->set_relation('situacao','tipo','nome');
$crud->callback_column('tempo',array($this,'calculodia'));
$crud->set_subject('para Responsavel');
$output = $crud->render();
$this->_example_output($output);
}
public function calculodia(){
$res = $this->db->get('template');
foreach ($res->result() as $linha){
return (strtotime($linha->data_final) - (strtotime($linha->data_inicio))) / (60 * 60 * 24). " dias"."<br/>";
}
}
Posted 21 February 2012 - 07:29 AM
...
$crud->columns('cliente','responsavel','situacao','tempo');
$crud->callback_column('tempo',array($this,'calculodia'));
...
And the callback that you use is wrong. In every callback I have some parameters that I pass through the callback. The $value and $row are auto-passed so you will not need anything else to add to your code. I know the documentation is not so good to understand that , so you will just need:
public function calculodia($value, $row){
return (strtotime($row->data_final) - (strtotime($row->data_inicio))) / (60 * 60 * 24). " dias";
}
Posted 21 February 2012 - 14:16 PM
Posted 18 May 2013 - 08:00 AM
how to pass multiple date into call back function? like "start date", "end date" into call back function.
Posted 20 May 2013 - 08:30 AM
unable to solve this problem. I want to calculate date between two days. i want to make leave managment page. please see the code.
function leave_management()
{
$crud = new grocery_CRUD();
$crud->set_table('leave_management');
$crud->columns('employee_name','from_date','to_date','duration');
$crud->callback_field('duration',array($this,'callback_to_date'));
$output = $crud->render();
$this->_example_output($output);
}
function callback_to_date($from_date, $to_date)
{//The format must be Y-m-d , m-d-Y, Y/m/d
$days = (strtotime($from_date) - strtotime($to_date)) / (60 * 60 * 24);
return $days;
}
Posted 20 May 2013 - 11:30 AM
The callback_field is used when you need to make changes to a specific field.
What you are trying to do is not achieved by using callback_field but by using callback_column where on a separate column you calculate the difference.
Posted 21 May 2013 - 05:42 AM
The callback_field is used when you need to make changes to a specific field.
What you are trying to do is not achieved by using callback_field but by using callback_column where on a separate column you calculate the difference.
Thnaks for your reply. I used both callback founcion but failed to solve it.
can you please tell me the solution ?
Posted 21 May 2013 - 07:54 AM
Problem solved by changing the date format in grocercrud config file.
can any one tell me, how could I change date format from UK date to SQL date format without chaning orginal grocery crud file?
suppose, I have a date like dd-mm-yyyy format. I want to convert it to yyyy-mm-dd format.
Posted 21 May 2013 - 08:17 AM
Changing the date in the config file is the preferred way!
It is not a change on the functionality of GC so you can change the settings there depending on your system.
Posted 24 May 2013 - 16:08 PM
Changing the date in the config file is the preferred way!
It is not a change on the functionality of GC so you can change the settings there depending on your system.
thanks. can you tell me how can I save the calculated data into database? I found the callback_column function result is not inserted into database. but i want to save the date calculation result. can you please give me idea of this problem to solve?
Posted 25 May 2013 - 05:05 AM
If you need to save the result you must also use the callback_field.
Posted 27 April 2016 - 08:46 AM
If you need to save the result you must also use the callback_field.
Hi,
Please post the callback_field code to save the difference of dates to database