how can i insert date time into MySQL date data type enabled row using Yii Framework.
how can i insert date time into MySQL date data type enabled row using Yii Framework.
for example
$post=new Post;
$post->create_time=new CDbExpression('NOW()');
// $post->create_time='NOW()'; will not work because
// 'NOW()' will be treated as a string
$post->save();
Documentation -> Tutorials -> The Definitive Guide to Yii -> Active Record
Also you can use like this
date_default_timezone_set('Asia/Calcutta'); // Add in your index.php file or you can set in php.ini
$post=new Post;
$post->created_on=date('Y-m-d H:i:s');
$post->save();
MySQL date fields want the format: YYYY-MM-DD HH:MM:SS
As detailed in a previous post, you can generate that with the php date() function. The previous posts don’t detail how to include a specific date (something other than MySQL NOW() or the current time)
//You need to define $hour,$minute,$second and so on
$sqldate = date('Y-m-d H:i:s',mktime($hour,$minute,$second,$month,$day,$year));
or if you are using a textField input
$sqldate = date('Y-m-d H:i:s',strtotime($textFieldValue));
Dear konarskit, lol for replying…
srinivasan,dada thanks for reply…
Dear jkofsky.thanks for effective reply…think it will be extend from here.LOL.
Thanks it helps me.