Yii2 Insert mysql data type time

Hi Guys,

I want to insert into mysql table data type time through model. Really I don’t have any idea about expressions!.

If I directly try at phpmyadmin I can insert “10:00:00” but via Yii2 model I can’t do it!

Hi Guys,

Any luck?

Hi Johnson,

Have you refer below two links


yii should not interfere with your database schema unless you tell it to, can you paste your code here and your table schema ?

Hi Guys,

Really thanks for your replies!. I tried to use the formatter but forgot to prepend “php:”. After looking deeply at the links posted by Mr. Chandran I found it!. :(

I changed to the following then worked fine for me.

Yii::$app->formatter->asDate($dateStr,"php:H:i:s"); // Example $dateStr -> "09:15:00" 

The table is like below

CREATE TABLE `timetable` (


  `school_id` int(11) NOT NULL,

  `class_id` int(11) NOT NULL,

  `from_time` time NOT NULL, //This is the one field

  `to_time` time NOT NULL //This the one field


Really thanks once again!