Reputation: 77089
I'm working on an extension intended for Magento 1.6 and above, and would like to use the general database syntax instead of the MySQL-specific one. I need a simple table to store a timestamp that I can use to select a set of orders.
I've looked through lib/Varien/Db and lib/Zend/Db, and the only date functions I see appear to be MySQL-specific:
lib/Varien/Db/Adapter/Mysqli.php: public function convertDate($date)
lib/Varien/Db/Adapter/Pdo/Mysql.php: public function convertDate($date)
In MySQL I would write:
INSERT INTO `marketing_services` SET `last_sent` = NOW();
I know the major RDBMS systems differ in their vocabularies and implementations for date functions, but does Magento have an abstraction for this and other date functions, and if not, how should I go about it?
Upvotes: 1
Views: 457
Reputation: 14182
Use this
/** @var $adapter Varien_Db_Adapter_Interface **/
$now = $adapter->formatDate(Varien_Date::now())
// or
$nowDateOnlyWithoutTime = $adapter->formatDate(Varien_Date::now(), false)
Upvotes: 2
Reputation: 146
This is Zend Framework code, nothing special in Magento with MySql. Source Code
Insert:
$adapter->insert('marketing_services', array('last_sent'=>new Zend_Db_Expr('NOW()'));
Update:
$adapter->update('marketing_services', array('last_sent'=>new Zend_Db_Expr('NOW()'));
Upvotes: 1