Yii 1.1: timestring

A Yii widget for displaying a human friendly view of two dates

This extension is a Widget that takes two dates and displays them in a human friendly string.

Here are some example outcomes

"2012-12-25" and "2012-12-31" will show as "25 to 31 Dec 2012"
"2012-12-25" and "2013-01-15" will show as "25 Dec 2012 to 15 Jan 2013"
"2013-01-05" and "2013-02-10" will show as "05 Jan to 10 Feb 2013"


Yii 1.1 or above


  1. Copy the extension to your protected/extensions folder.
  2. In a View file, insert as a Widget using "YYYY-mm-dd" formatted parameters for 'startDate' and 'endDate'. Set 'duration' to true to show the number of days in brackets as a suffix.
$this->widget('TimeString', array(
    'startDate'=>$data->start_date, // assuming $data->start_date is "2012-12-25"
    'endDate'=>$data->end_date,     // assuming $data->end_date is "2012-12-31"

Total 4 comments

#11693 report it
Peter JK at 2013/01/27 09:57pm

I see,

thx for your response. how about convert this extension into helper function? so, i could make a special AR function on model, and then call that function from CGridView? just idea..

#11684 report it
CobraF at 2013/01/27 08:09am

Hi Peter, I tried using the example I have written below but without luck. The page renders up to the point where the widget code is and then stops rendering any further. Did you have any further luck? In the following example, I used


instead of


as "widget" is not a method of CGridView.

<?php $this->widget('zii.widgets.grid.CGridView', array(
            'value'=>'parent::widget(\'TimeString\', array(
)); ?>
#11605 report it
CobraF at 2013/01/22 05:46pm
RE: CGridView

Hi Peter, Thank you for your question. I haven't tried this in CGridView, but I will try it and come back to you.

#11561 report it
Peter JK at 2013/01/20 10:04pm

is it working on CGridView?..

Leave a comment

Please to leave your comment.

Create extension