Format Date/Time in AR

Hi,

when i use this in my AR Model in the rules section:


array('paket_datum','type','type'=>'date','dateFormat'=>'d.M.yyyy'),

the date will just be validated after the user input. is there a way that i can tell yii

to automatically use my preferred date/time format? so that this format will be used

for every date field i use. display, convert to the database format and back. or do i have to

manually always convert and write my own code?

i think there is an error in the message when you enter a wrong date. the message says

"paket_datum must be date" but it should be "paket_datum must be d.M.yyyy" or not?

Thanks

This is what I did in my project. May be it’ll help you.

In my model class, in afterFind function i’ve added the following line


$this->dob = date("d M Y",$this->dob);

and in beforeSave function, i’ve added the following lines




if(!is_numeric($this->dob)){

	$this->dob = strtotime($this->dob);

}



As for your rule, yes you can customize message, just add a new item in rules array with key = "message"


array('paket_datum','type','type'=>'date','dateFormat'=>'d.M.yyyy', 'message'=>'paket_datum must be d.M.yyyy'),

Hope this helps.

thanks very much, works well. in my case i used


$this->paket_datum = date("d.m.Y",strtotime($this->paket_datum));

in afterFind, becaus in my database there is not a timestamp, but

the mysql date format.

I’ve used this extension here with good success. Also check out the source, it automates, what you do manually here:

http://www.yiiframework.com/extension/i18n-datetime-behavior/

Hi!

I have a problem in CGridView.

I’m use the i18N Datetime Behavior extension. (http://www.yiiframework.com/extension/i18n-datetime-behavior/)

This work’s! But, in CGridView, the extension sending the formatted date (d/m/Y)…

Can you help me?