Yii Framework Forum: Get Different Between Two Dates - Yii Framework Forum

Jump to content

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

Get Different Between Two Dates Rate Topic: -----

#1 User is offline   Hasaranga 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 26-March 13

Posted 03 April 2013 - 02:51 AM

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?
0

#2 User is offline   Ghanshyam 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 18-March 13
  • Location:Ahmedabad

Posted 03 April 2013 - 03:08 AM

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

0

#3 User is offline   Hasaranga 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 26-March 13

Posted 09 April 2013 - 02:22 AM

View PostGhanshyam, on 03 April 2013 - 03:08 AM, said:

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
0

#4 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 09 April 2013 - 02:31 AM

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

#5 User is offline   epulgaron 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 19-February 14

Posted 16 April 2014 - 10:05 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 Postsensorario, on 09 April 2013 - 02:31 AM, said:

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

0

#6 User is offline   jkofsky 

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

Posted 16 April 2014 - 01:56 PM

View Postepulgaron, on 16 April 2014 - 10:05 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)
{

$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
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