This behavior can be attached to ActiveRecord model for automatically conversion MySQL date and datetime field to PHP5 DateTime object.
Extract the release file and put it under protected/extensions.
In your ActiveRecord model, add the following code:
public function behaviors() { return array('edatetimebehavior' => array('class' => 'ext.EDateTimeBehavior')); }
You may have to change 'ext.EDateTimeBehavior' if you don't put the file to 'protected/extensions'.
Nothing much, now your date/datetime attributes can be used as a PHP5 DateTime object.
Enjoy the convenience.
Inspired from i18n-datetime-behavior
This is my first extension, any comments are welcome :)
Total 3 comments
Hi
I think you should not initialized DateTime with "@timestamp".
From php.net: The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).
DateTime.setTimezone(946684800) should work. Or:
So I will be able to use php date() to change the display format?
Leave a comment
Please login to leave your comment.