Magento 1.6: Using MySQL datetime fields with model resources

I created a database table with a DATETIME field named "release_date" and the model / resource model seems to work fine. However, I want to get and set the "release_date" as a Zend_Date object. And I also want to make sure that it is always stored and retrieved as UTC.

Do you have any suggestions on how I can do this, or perhaps the best solution for everyone?

+4
source share
1 answer

You can process it in your resource model, for example:

protected function _beforeSave(Mage_Core_Model_Abstract $object) { ... $date = $object->getReleaseDate(); // convert from your server/client timezone to UTC if needed $object->setReleaseDate($this->formatDate($date)); ... } protected function _afterLoad(Mage_Core_Model_Abstract $object) { ... $date = new Zend_Date($object->getReleaseDate()); // convert to your server/client timezone from UTC if needed $object->setReleaseDate($date); ... } 
+3
source

Source: https://habr.com/ru/post/926604/


All Articles