Title: Inserting dates to Oracle database through Zend_Db
Tags: oracle;zend-framework
Question: I am trying to add an entry to an Oracle table which has a date field. So far, I've only been able to do it like this:
$createdDate = $entry-&gt;createdDate-&gt;toString('yyyy-MM-dd');
$data = array(
'ID' =&gt; $entry-&gt;id,
'STATE' =&gt; $entry-&gt;state,
'CREATED_DATE' =&gt; new Zend_Db_Expr("to_date('$createdDate', 'YYYY-MM-DD')")
$this-&gt;_getGateway()-&gt;insert($data);
Is there a better way? This solution smells dirty to me.

Here is the accepted answer: You should be able to do this instead:
$createdDate = $entry-&gt;createdDate-&gt;toString('yyyy-MM-dd');
$data = array(
'ID' =&gt; $entry-&gt;id,
'STATE' =&gt; $entry-&gt;state,
'CREATED_DATE' =&gt; new Zend_Db_Expr("date '$createdDate'")
$this-&gt;_getGateway()-&gt;insert($data);
The only difference is the use of an ANSI date literal in line 5.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:09/13/10', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<oracle><zend-framework>', 'Title': 'Inserting dates to Oracle database through Zend_Db', 'ViewCount': 1902, 'id': 3698999, 'user_AboutMe': '<p>Software engineer hailing from Zagreb, Croatia.</p>\n', 'user_AccountId': 22198.0, 'user_DisplayName': 'Ariod', 'user_Reputation': 5657.0, 'user_Views': 358.0, 'user_id': 54522.0}}