Yii - ¿Qué métodos usar para procesar este cambio de fecha?

I'm not sure where to make this. Here's part of my config file:

        'defaultController' => 'event/index', //events as default

            'format' => array(
                    'datetimeFormat' => 'dd/mm/yyyy hh:mm',
                    'dateFormat' => 'dd/mm/yyyy',
                    'timeFormat' => 'hh:mm',

So: I'm retrieving the date as a string like this:


So I need to convert this string to: 02-11-2010 .

He intentado esto:


Yo obtengo:

"A non well formed numeric value encountered"

¿Por qué?


Update: Used: yii::app()->dateFormatter->format('dd', $data); //to return the day; Used: yii::app()->dateFormatter->format('MMMM', $data); //to return the month;


preguntado el 04 de julio de 12 a las 00:07

Has mirado CDateFormatter? -

I now have. thanks. I've change the config file, and I was excepting the date to change from yyyy-mm-dd a dd/mm/yyyy . No luck. the data coming from the db still preserves their stored format. :( -

1 Respuestas

We have in config:

 'components' => array(
       'format' => array(
            'datetimeFormat' => 'm/d/Y h:i A',
            'dateFormat' => 'm/d/Y',
            'timeFormat' => 'h:i A',

and we use like:

y puedes usar Yii::app()->format formatear

Respondido 04 Jul 12, 08:07

So, when you receive data from the database on yyyy/mm/dd you use your format settings to change it. But on this case, I would have the need for two different formats. One for the forms other for presentation views as stated on original question. So I guess I can't follow that path. Anyway, is format an alternative method of CDateFormatter ? Gracias. - MEM

format is an application component, and it's a wrapper to CDateFormatter. The format method takes format parameters, it's up to you what parameters you give. - Pentium10

Ok. I've tried that. A date is coming from my database as yyyy-mm-dd and I wish to convert it as dd/mm/yyyy so I've made the appropriate changed on config. However, the date doesn't get formated. It preserves the mysql returned format. Shouldn't that change automatically ? - MEM

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.