Datetime To Timestamp Behavior

I want to create a behavior that converts datetime to timestamps, and this is what I’ve come up with so far:

    public function behaviors()


		return [

			// convert datetime to timestamp


				'class' => DatetimeToTimestampBehavior::className(),

				'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'created_at'],

				'value' => $theDatetimeValue,




The behavior:

class DatetimeToTimestampBehavior extends Behavior


	public $attributes;

	public $value;

	function getValue($event) {

		return strtotime($this->value);



…however it’s not working at all. It’s as if the event AFTER_FIND is not registered, even though i’m using the active record method $category = Category::findOne(1);

I’ve tried adding a die(‘hello’); in the getValue() function, but the function does not seem to execute.

What am I missing?

I haven’t created behaviors until now but it seems you need to define Event-Handlers (yii\base\Beaviour::events()) in your behavior?!

Your behavior is extended from a wrong class - change definition to following:

class DatetimeToTimestampBehavior extends yii\behaviors\AttributeBehavior

Thanks, that solved it!