mithlesh
(Mithlesh1007)
1
Hi,
My application is hosted on the shared hosting server. The database timezone is EST.
I want my application to use IST Timezone everywhere where date time is concern, ex- (create,view, update etc).
I searched the forum and added the below line in main.php but nothing happened.
‘timeZone’ => ‘Asia/Calcutta’,
Can anyone please suggest.
seenivasan
(Chellamnivas)
2
Dear Friend
By calling this code in a view
Yii::app()->timeZone='Asia/Calcutta';
echo Yii::app()->timeZone;
echo "</br>";
echo date('Y/m/d H:i:s',time());
echo "</br>";
Yii::app()->timeZone='America/Los_Angeles';
echo Yii::app()->timeZone;
echo "</br>";
echo date('Y/m/d H:i:s',time());
echo "</br>";
I am getting this as output.
Same thing happens when I configure main.php
Regards.
mithlesh
(Mithlesh1007)
3
Hi seenivasan,
Thanks for your prompt response.
Sorry but i didnt get you, do you mean to say to paste Yii::app()->timeZone=‘Asia/Calcutta’; in main.php, so that it will take effect in view also.
seenivasan
(Chellamnivas)
4
Dear Friend
If I add the following line to main.php
timeZone'=>'America/Los_Angeles',
and if I call the following code in a view
echo Yii::app()->timeZone;
echo "</br>";
echo date('Y/m/d H:i:s',time());
what I am getting is
If I add the following line to main.php
timeZone'=>'Asia/Calcutta',
and if I call the following code in a view
echo Yii::app()->timeZone;
echo "</br>";
echo date('Y/m/d H:i:s',time());
what I am getting is
mithlesh
(Mithlesh1007)
5
Hi seenivasan,
I am using the below code to insert the current time and after that the code to view the comments of today’s date only.
since the database time is in EST zone now function saves the time in EST.
Can you please suggest.
protected function beforeSave()
{
$this->create_time=new CDbExpression('NOW()');
return TRUE;
}
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('comment' ,array(
'pagination'=>array(
'pageSize'=>50,
),
'criteria'=>(array(
'condition'=>'DATE(create_time) = CURDATE()',//datefield
'order'=>'create_time DESC',
)
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
seenivasan
(Chellamnivas)
6
Dear Friend
After configuring in main.php
timeZone'=>'Asia/Calcutta',
You modify the method beforeSave
protected function beforeSave()
{
$this->create_time=date('Y-m-d H:i:s',time());
return TRUE;
}
function actionIndex()
{
$today=date('Y-m-d',time());
$dataProvider=new CActiveDataProvider('comment' ,array(
'pagination'=>array(
'pageSize'=>50,
),
'criteria'=>(array(
'condition'=>"DATE(create_time) =$today",//datefield
'order'=>'create_time DESC',
)
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
mithlesh
(Mithlesh1007)
7
Hi seenivasan,
Thanks for your valuable time and support.
It worked as expected.