Get Different Between Two Dates

I want to calculate the different between two days not a specific two dates, the date are dynamic. I means the,

$date1 = "2013-03-24";

$date2 = "2013-06-26";

$diff = abs(strtotime($date1) - strtotime($date2);

this work properly but if we use variable for the $date1 and $date2 it means not using specific dates and use dynamic date values for above strtotime() function it’s not work properly.

So how can I do this?

You may be try like that…may be useful.




$eventdate = $data->start_date;

$currentdate = date('Y-m-d');

$datediff = (strtotime($eventdate) - strtotime($currentdate)) / (60 * 60 * 24);



No friend considering strtotime() function the variable are not assign when we put like this,strtotime($eventdate). I don’t know why? that the problem i have

I dont understand why you do by hand what php can do with DateTime class. I really dont understand.

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

Double Post