Expression cannot be converted to int

I need help in my active record

I tried all my cards for this :D but still, I failed so now I’m in need of assistance.

i have a function like this

function updateDuration()	{

	$this->duration = new Expression("month(startdate) - month(enddate)");




$this->duration // integer type in database

Error is

Object of class yii\db\Expression could not be converted to int

What should i do ? ? ?

Really needed help about this. Thank you very much! :D :D :D

FYI! I love YII2!!! It’s great. :D

I’m just not someone who’s willing to wait. So i tried my other solution which is

function updateDuration()	{

	$this->duration = static::find()->select([

		"duration" => new Expression("month('2016/01/01') - month('2016/02/13')")


	return $this->save();


Now it works! :D But still, I think this is not a good approach since normally, the likes of this should be done in just one query.

If you have any suggestion, I’m willing to learn :D :D :D

Thanks! :D :D :D