i18n-datetime-behavior Automatic conversion for I18N date and datetime fields

  1. Documentation
  2. Change Log

This extension is a behavior that can be used in models to allow them to automatically parse and format i18N date formats.

The behavior scans for date and datetime fields in the model attributes, and do the conversions needed.


  • Yii 1.0.9 or above
  • You need to have defined your desired language at the entry script.
  • Extract the release file and put it under protected/extensions

In you model, add the following code:

public function behaviors()
    return array('datetimeI18NBehavior' => array('class' => 'ext.DateTimeI18NBehavior')); // 'ext' is in Yii 1.0.8 version. For early versions, use 'application.extensions' instead.

IMPORTANT! This behavior changes afterFind and beforeSave events. If your model have to have coding, please, don't forget to add the parent reference:

protected function beforeSave(){
	if (!parent::beforeSave()) return false;
	....your code

The same for afterFind method. Otherwise, this behavior will not make effect.

Note: This extension was made for MySQL. But, it can be easily changed to be useful to other databases.

Note2: Actually, the extension have problems with datetime fields, just working with date fields (FIXED)

Use version 1.1 if you are using Yii 1.0.9. If not, use the original version (with the bug described on note #2)

Change Log

September 30, 2009

Fixed issue with optional date/datetime fields and incorrect convertion on datetime fields (works only with Yii 1.0.9. If you use this version, download I18N-datetime-behavior 1.1. If not, use the original version)

August 17, 2009
  • Initial release.

** NEW (GITHUB) Extension added to GitHub

34 1
4 143 downloads
Yii Version: 1.1
License: (not set)
Category: Date and Time
Developed by: ricardograna
Created on: Aug 18, 2009
Last updated: 5 years ago


show all