find date difference of from two datepicker

I have tow date fields using date picker ,

code for both is as below ( name is differtne ) ,

<?php

	&#036;this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array(


			'name'=&gt;'LeaveSummary[LS_TO]',


			'model'=&gt;&#036;model,


			'attribute'=&gt;'LS_TO',


			'value'=&gt;'yy-mm-dd',


			'options'=&gt;array(


				'showAnim'=&gt;'fold',


				'dateFormat'=&gt;'yy-mm-dd',


			),


			'htmlOptions'=&gt;array(


				'style'=&gt;'height:20px;'


			),


			));				


	?&gt;

– what i have to do is to find date diffrerence from both datepicker ( in days like 1,2,3, … )

Maybe …

  1. Convert each date string to a timestamp using CDateTimeParser::parse().

  2. Get the difference between 2 timestamps.

  3. Devide the diff by (24 * 60 * 60).

I’m not sure if it will work 100% or not. Just give it a try. :)

hi i am trying to show in a custom column grid that shows me the remains of two of the fields grid, and what would they be fecha_det_a1 fecha_ocu_a1

this function should develop in my admin because that’s where I want it to display. Already declared the variable in the model (), now this is the function:

<?php

function dateDiff($start, $end)

{

$start_ts = strtotime($start);

$end_ts = strtotime($end);

$diff = $end_ts - $start_ts;

return round($diff / 86400);

}

$fdfo=dateDiff($model->fecha_det_a1,$model->fecha_ocu_a1);

?>

When I invoke the function within the grid, I do soÑ

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘id’=>‘anexo1-grid’,

‘itemsCssClass’=>“table table-striped”,

‘dataProvider’=>$model->search(),

.

.

‘columns’=>array(

‘id’,

array(‘name’=>‘no_hc_a1’,‘value’=>’$data->no_hc_a1’),

array(‘name’=>‘entidadhc_fk’,‘value’=>’$data->entidadhcFk->enthc_nombre’),

array(‘name’=>‘orga_hc_siglas’,‘value’=>’$data->entidadhcFk->orgaFk->orga_hc_siglas’),

.

.

array(‘name’=>‘fdfo’,‘value’=>$fdfo),

.

.

array(

‘class’=>‘CButtonColumn’,

),

),

)); ?>

but when I go to access the admin view returns me the following error:

call_user_func_array() expects parameter 1 to be a valid callback, no array or string given

could you help me? thanks

Is dateDiff() declaired in the model? (nitpik: Add Public to it)

$fdfo=dateDiff($model->fecha_det_a1,$model->fecha_ocu_a1); is in the view? If yes then I think you need to do:


$fdfo=$model->dateDiff($model->fecha_det_a1,$model->fecha_ocu_a1);

You could also add a public $fechaDateDiff to the model, and set it in the afterFind() function. Then you could diplay it with $model->fechaDateDiff

Just some thoughts 8)