Prabhakar Siddhant
Prabhakar Siddhant

Reputation: 131

Date Virtual field - cakephp 2.0

Small logical problem. I'm learning CakePHP 2.0 and i've used virtual fields before but this time i want to format the DATETIME fields.

As output, I get YYYY-MM-DD (numeric like 2010-10-31) but I want the output to be just September, 2005

what logic should i apply to get this in a virtual field, or if there's a better approach pls give me a direction.

Thanks.

Upvotes: 1

Views: 787

Answers (1)

Jorge Ramirez
Jorge Ramirez

Reputation: 91

If your are using Mysql you can use DATE_FORMAT function.

Add a virtual field to your Model file like this:

class Yourmodel extends AppModel {

     var $virtualFields = array(
                'formateddate' => 'DATE_FORMAT(Yourmodel.mysqldate,"%d/%m/%Y")');

.
.
.
}

Change the format string to your needs.

Upvotes: 1

Related Questions