application wide functions


an example function CDbExpression() to handle MS-SQL getdate() vs MySQL NOW() ;

you can have whatever functions here which would be used application wide.

add files in \protected\components\functions\Fn.php

class fn extends CApplicationComponent


	public function init() {




	 * handle NOW() function for ms-sql server

	 * @param string $exp

	 * @return string


	public static function CDbExpression($exp, $db='db') {

		if($exp == 'NOW()') {

			if (substr(Yii::app()->{$db}->connectionString, 0, 7) === 'sqlsrv:') {

				return new CDbExpression('GETDATE()');




		return new CDbExpression($exp);




in protected\config\main.php add line





in any code, replace

new CDbExpression('NOW()');



Thanks man, but it didn’t work. I always receive:

GETDATE() as return.

Any Ideas?