Issue
I have a table which contains the field "created". It is a DateTime type. I am getting the data using:
$this->MyModel->find("all");
I only need the time (12:00:00) from the DateTime (2013-12-27 12:00:00). In SQL it is very easy to do by using DATE_FORMAT() but I have no Idea how to do this in cake... I want to do this in the model by getting the data from DB and not one by one in the view using TimeHelper.
Solution
You can use a virtual field
class MyModel extends AppModel {
var $virtualFields = array(
'time' => 'DATE_FORMAT(myModel.date_time,"%H/%i/%s")');
//the rest of the class
}
Answered By - Kai
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.