<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'Your-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name'=>'age','value'=>'round((strtotime($data->result_date)-strtotime($data->swimmer->date_of_birth))/(366*24*60*60))'),//this gives the age, modify attributes according to yours
In your model result, add these lines where required:-
public $age; // to be used to store age
public function rules()
array('attrib1, attrib2, attrib3, age', 'safe', 'on'=>'search')
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('swimmer');
$criteria->compare('substring(result_date,1,4)-substring(swimmer.date_of_birth,1,4)',$this->age);
.........
..........
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'age'=>array(
'asc'=>'(substring(result_date,1,4)-substring(swimmer.date_of_birth,1,4))',
'desc'=>'(substring(result_date,1,4)-substring(swimmer.date_of_birth,4)) DESC'
),
..........
...........
.....