Yii Framework Forum: find date difference of from two datepicker - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

find date difference of from two datepicker find date difference of from two datepicker Rate Topic: -----

#1 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 498
  • Joined: 21-May 11
  • Location:India

Posted 07 June 2011 - 06:57 AM

I have tow date fields using date picker ,

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

<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'LeaveSummary[LS_TO]',
'model'=>$model,
'attribute'=>'LS_TO',
'value'=>'yy-mm-dd',
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>


-- what i have to do is to find date diffrerence from both datepicker ( in days like 1,2,3, ... )
Thanks,
Kiran Sharma.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,112
  • Joined: 16-February 11
  • Location:Japan

Posted 08 June 2011 - 03:55 AM

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. :)
0

#3 User is offline   epulgaron 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 19-February 14

Posted 16 April 2014 - 10:09 AM

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

View Postsoftark, on 08 June 2011 - 03:55 AM, said:

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. :)

0

#4 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 16 April 2014 - 01:39 PM

View Postepulgaron, on 16 April 2014 - 10:09 AM, said:

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)
{

...
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'=>'fdfo','value'=>$fdfo),
...
)); ?>

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)
Do, or do not. There is no 'try.' Jedi Master Yoda
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users